- 1
You need to change the code to skip the even numbers, so that the logic only applies to odd numbers in the range.
Python core (continue statement)
7 Antworten
+ 4
Please show us your attempt so far so we may help. Thanks.
To determine if a number is odd:
if (num % 2 == 1):
This will become True if num is odd since dividing an odd number by 2 will have 1 remainder. e.g. 15 % 2 == 1 (True)
+ 3
Krunal Ramraje
If you want to skip even numbers then just add 'step' argument to your range function:
for x in range(1, n, 2):
This will iterate from 1 to n with step of 2 (or adding 2 every loop).
Iteration
1
3
5
7
9
...
n
- 1
I want to skip the even numbers
- 1
Thankyou done for this
- 1
this guy probably decided to take the programming course he missed in half an hour
- 2
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)
- 3
Write a program to take two integers as input and output their sum.
Sample Input:
2
8
Sample Output:
10