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)
4 Answers
+ 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)
+ 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)
+ 1
A͢J - SÍoÍlÍoÍHÍeÍlÍpÍeÍrÍ thanks a lot AJ !đ§Ą
0
Lothar great ! I got it now thanks lothar đ§Ą