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 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)

+ 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 🧡