- 2
How can I change the code to make it print odd numbers only?
n = int(input()) for x in range(1, n): if x % 3 == 0 and x % 5 == 0: print("SoloLearn") elif x % 3 == 3: print("Solo") elif x % 5 == 0: print("Learn") else: print(x)
3 Respuestas
+ 5
If you don’t know how do do something in programming, do this:
1. learn it - Use some kind of course online to learn a topic. If you still don’t know⬇️
2. Practice it- practice with challenges, code coach and codes. If you still don’t know⬇️
3.Search it - Use Google or SoloLearn search bar before asking question. If you still don’t know⬇️
4.Ask - Ask the questions on SoloLearn, Quora, or StackOverflow. If you still don’t know⬇️
5. Sleep- just clear your mind and try these steps again
+ 4
You can find a way here:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2281/
Another way can be found here :
https://www.sololearn.com/learn/Python/2434/
Please review the course😊
0
Odd number are those which have not zero as remainder when divided by 2 so x % 2 if it is zero so x is even otherwise it is odd.so you have to added before first if another if that check if x is odd
if x %2 != 0:
if x % 3 == 0 .......
Or you can added another and condition if x % 5 == 0 and x % 2 != 0 :......