0

# Why does this code not work ?

It solves the first case ,but not the second and I can't see what it is because I don't have pro. n = int(input()) for x in range(1, n): if x % 2 == 0: continue elif x % 3 == 0: print("Solo") elif x % 5 == 0: print("Learn") elif x % 3 == 0 and x % 5 == 0: print("SoloLearn") else: print(x)

19th Dec 2021, 9:04 AM
Wellsie
4 Antworten
+ 7
Wellsie , you can run the code with one if ... and then following by elif ... and else. but the condition that checks for divisible by 3 and by 5 has to be the second condition to check: 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)
19th Dec 2021, 5:09 PM
Lothar
+ 2
Wellsie 1 - Don't write second case as elif because in first case you have used continue. if x % 2 == 0: continue if x % 3 == 0: print ("Solo") elif x % 5 == 0: print ("Learn") This is enough 2 - Write last condition at second place. Solution: for x in range(1, n): if x % 2 == 0: continue 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)
19th Dec 2021, 9:31 AM
A͢J
+ 1
19th Dec 2021, 10:05 AM
Wellsie
0
Lothar great ! I got it now thanks lothar 🧡
19th Dec 2021, 9:16 PM
Wellsie