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

17th Jan 2022, 10:30 AM
KINGFISHER
KINGFISHER - avatar
4 odpowiedzi
+ 2
You can also use continue statement to skip even numbers. for x in range(1, n): if x % 2 == 0: continue elif.....
17th Jan 2022, 10:42 AM
Simba
Simba - avatar
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:
17th Jan 2022, 2:02 PM
Brian
Brian - avatar