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

17th Feb 2021, 8:42 AM
Krunal Ramraje
Krunal Ramraje - avatar
7 Respostas
+ 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)
17th Feb 2021, 8:50 AM
noteve
noteve - avatar
+ 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
17th Feb 2021, 8:53 AM
noteve
noteve - avatar
- 1
I want to skip the even numbers
17th Feb 2021, 8:53 AM
Krunal Ramraje
Krunal Ramraje - avatar
- 1
Thankyou done for this
17th Feb 2021, 8:55 AM
Krunal Ramraje
Krunal Ramraje - avatar
- 1
this guy probably decided to take the programming course he missed in half an hour
17th Feb 2021, 9:44 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
- 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)
17th Feb 2021, 8:52 AM
Krunal Ramraje
Krunal Ramraje - avatar
- 3
Write a program to take two integers as input and output their sum. Sample Input: 2 8 Sample Output: 10
17th Feb 2021, 8:56 AM
Krunal Ramraje
Krunal Ramraje - avatar