Fizzbuzz python sololearn решение

Python code fizz buzz

I think the descrition or the solution is not correct. It sais fir each number which is a multiple of 3 the word solo should be printed but when it gets to number 6 which is a multiple of 3 in my understanding nothing should be printed acc requested output

n = int(input()) for sololearn in range(1,n,2): if sololearn % 3 == 0 and sololearn % 5 == 0: print(‘SoloLearn’) continue elif sololearn % 3 == 0: print(‘Solo’) continue elif sololearn % 5 == 0: print(«Learn») continue print(sololearn) #there is an error in all ans. #in second line (the for loop), but its now resolved.

n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0 and x != 6 and x != 12: print(«Solo») elif x % 5 == 0 and x != 10: print(«Learn») else: if not x % 2 == 0 : print(x)

n = int(input()) for x in range(1, n, 2): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x)

n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 2 == 0: continue elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x) By using elif x % 2 == 0 we can skip the even values ranging from 1 to n. It will skip the even values and then further go for next line elif statements.

my code is: n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») elif not x%3==0 or x%5==0: print(x) continue I think the answer presents mistake?

Читайте также:  Python код ответа сервера

Often have questions like this?

Learn more efficiently, for free:

Источник

Fizz buzz

n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x) FizzBuzz — это популярная задача, которая часто дается в ходе собеседования. Предложенный код разрешает проблему FizzBuzz и использует слова «Solo» и «Learn» вместо «Fizz» и «Fizz». Он берет ввод n и выводит числа от 1 до n. Для каждого числа, кратного 3, печатает «Solo» вместо числа. Для каждого числа, кратного 5, печатает «Learn» вместо числа. Для чисел, кратных 3 и 5, выводит «SoloLearn». Вам необходимо написать код, чтобы пропускать четные числа, чтобы данная логика применялась только к нечетным числам диапазона. Что нужно сделать в этом задании.

n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») _______________ elif x%2 == 0: continue _______________ elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x)

n = str(int(input()) for i in range( 1, n ) if i % 3 == 0: print(«solo») if i % 5 == 0: print(«learn») if (i % 3) and (i % 5): print(«sololearn») что не так я пробывал не идет

n = int(input()) for x in range(1, n): if x % 2 != 0 : if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x)

Fizz buzz n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x)

Often have questions like this?

Learn more efficiently, for free:

Источник

Please, I need solution for 30 project(FizzBuzz) in python

https://code.sololearn.com/cWB3R3j6Mqar/?ref=app Question: FizzBuzz is a well known programming assignment, asked during interviews. The given code solves the FizzBuzz problem and uses the words «Solo» and «Learn» instead of «Fizz» and «Buzz». It takes an input n and outputs the numbers from 1 to n. For each multiple of 3, print «Solo» instead of the number. For each multiple of 5, prints «Learn» instead of the number. For numbers which are multiples of both 3 and 5, output «SoloLearn». You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range.

I got the solution. The correct code is: https://code.sololearn.com/c73fF7Zjde64/#py n = int(input()) for x in range(1, n,2): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x)

Arsenic «learn»? People don’t come here to learn. They come for the xp, levels, badges, views, upvotes, and followers.

Your code works as expected but you haven’t implemented the odd/even condition yet (last paragraph of the task description)

n=int(input()) for i in range(1,n): while i

Shlok the range function has a third argument, the step. If you don’t specify it python uses the default value 1. Change it to skip even numbers. (There are other ways to achieve this.)

here is the answer. this could help. n = int(input()) for x in range(1, n): if x % 2 == 0: continue elif x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x)

i have same problem with fizz buzz, when i change x%3==0 to x%3==2, it can solve first question, but not second question. And when i change x%5==0 to x%5==3, it can solve second question but not third question. Then it continue until i feel so headache.

n = int(input()) for x in range(1, n): while x < n : if x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") if x % 2 == 0 : continue else: print(x) I tried this but it didn't work out is there something else i can try or is there just wrong with my syntax I also tried using elif instead of if but i had a similar problem. It said 'continue' does not fit in the loop

Often have questions like this?

Learn more efficiently, for free:

Источник

How to write the problem «FizzBuzz»?

Artem n = int(input()) for sololearn in range(1, n): if sololearn % 3 == 0 and sololearn % 5 == 0: print(‘SoloLearn’) continue elif sololearn % 3 == 0: print(‘Solo’) continue elif sololearn % 5 == 0: print(«Learn») continue print(sololearn)

Abhay, dbite if you adjust the range then you can eliminate the ‘if sololearn%2==0:’ logic for skipping even numbers. Have the range start with 1 and increment by 2 so that even numbers are excluded. for sololearn in range(1, n, 2): This is easier to read and it runs faster with less memory. Now even the remaining continue statement is removed.

dbite you need to understand how to use continue ,all those continues you have used are useless as you are already checking using elif and the control goes back to loop immediately if any condition is satisfied , the question asks to not print for even number ,so what you should do is add the following check when entering for loop if i%2==0: continue it will ensure that no even number is printed or checked for and after that you can include other elif statements

dbite whats the problem there? If you need not to print even numbers then then follow @Abhay solution. I add that if i%2 != 0 : print(sololearn) reduse one line more. If you don’t have to consider even numbers totally then @Brian solution works better. Mention what problem you are getting.

dbite i added it already for that and @Abay also if i%2!=0 : #skip printing even numbers. print(sololearn)

Often have questions like this?

Learn more efficiently, for free:

Источник

How can I solve FizzBuzz problem?

the last section says you need to skip even numbers. add another if statement. if x % 2 == 0: # how to test for an even number . .

as Slick suggested, I will only add if x % 2 == 0: continue # to pass even nums # try to put this condition in the correct place

Post your code so we can help. If you haven’t written any yet, i suggest you go back over the previous lesson

n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print(«SoloLearn») elif x % 3 == 0: print(«Solo») elif x % 5 == 0: print(«Learn») else: print(x) # I can’t solve it yet. #The question is: The given code solves the FizzBuzz problem and uses the words «Solo» and «Learn» instead of «Fizz» and «Buzz». It takes an input n and outputs the numbers from 1 to n. For each multiple of 3, print «Solo» instead of the number. For each multiple of 5, prints «Learn» instead of the number. For numbers which are multiples of both 3 and 5, output «SoloLearn». You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range. # so help me there.

Agregar en el primer elif lo siguiente: elfi x % 2 == 0: print(«») no hay necesidad de imprimir el número, solo que sea la primera iteración y que omita el número par.

You need to follow the suggestions already given to you. twice. In the correct place add: elif x % 2 == 0: continue

Often have questions like this?

Learn more efficiently, for free:

Источник

Оцените статью