+ 1
Can anybody tell me other method for this code.
Question->ââân = int(input()) for x in range(1, n): 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)âââ My answer-> n = int(input()) for x in range(1, n, 2): 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) I just changed interval of range by 2.
4 Answers
+ 2
You can also use continue statement to skip even numbers.
for x in range(1, n):
if x % 2 == 0:
continue
elif.....
0
Kunal B the code looks very good.
You could reduce the logic just a little.
if x % 3 == 0 and x % 5 == 0:
Reduces to the equivalent:
if x % (3*5) == 0: