+ 1
How to write the problem "FizzBuzz"?
Who can help write the code?
7 odpowiedzi
+ 2
Please, show us your attempt first. We don't do homework assignments here.
+ 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)
+ 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.
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
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..?
0
Jayakrishna🇮🇳 output must be:
1
Solo
Learn
My output is:
1
2
Solo
4
Learn
(and so on)
0
dbite i added it already for that and @Abay also
if i%2!=0 : #skip printing even numbers.
print(sololearn)