0

Can anyone help me to solve the fizzbuzz problem of Python? I have written the code which qualifies only the first test case.

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

25th Mar 2021, 12:02 PM
Akash
Akash - avatar
2 ответов
+ 2
1. Move continue to the top for the first if statement and change the condition to == instead. Now you can get rid of the last else and you won't need to nest the rest of the if-elif-else statements. 2. The order of your if-elif statements matters. If the first one or second are True the third will never be reached! Etc
25th Mar 2021, 12:15 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
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) # fix indentation of your 1st condition and it is supposed to pass the %2 == 0 not to restrict it so a continue statement will do the trick # 2nd condition should be the combined one # the rest of your code is correct
25th Mar 2021, 12:21 PM
iTech
iTech - avatar