+ 1

How to write the problem "FizzBuzz"?

Who can help write the code?

10th Nov 2020, 6:49 PM
dbite
dbite - avatar
7 ответов
+ 2
Please, show us your attempt first. We don't do homework assignments here.
10th Nov 2020, 7:14 PM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 1
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)
10th Nov 2020, 7:17 PM
dbite
dbite - avatar
+ 1
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.
11th Nov 2020, 5:00 AM
Brian
Brian - avatar
0
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
10th Nov 2020, 9:00 PM
Abhay
Abhay - avatar
0
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..?
11th Nov 2020, 2:10 PM
Jayakrishna 🇮🇳
0
Jayakrishna🇮🇳 output must be: 1 Solo Learn My output is: 1 2 Solo 4 Learn (and so on)
11th Nov 2020, 2:16 PM
dbite
dbite - avatar
0
dbite i added it already for that and @Abay also if i%2!=0 : #skip printing even numbers. print(sololearn)
11th Nov 2020, 3:53 PM
Jayakrishna 🇮🇳