Write a program in python 'to print the odd numbers between 1 to 30'.
No Wrong Answer...
Answers
Answered by
12
for x in range(30):
if x % 2 == 0:
continue
else:
print(x)
hope it helps you. Goodluck.
Answered by
2
A python program to print the odd numbers between 1 and 30:
for i in range(1, 31):
if i % 2 != 0:
print(i)
- The for loop is used to iterate over a range of numbers from 1 to 30 (range(1, 31)). The variable i is used to store the current number in each iteration.
- The if statement is used to check whether i is odd or not. To do this, the modulus operator (%) is used to determine the remainder when i is divided by 2.
- The % symbol in Python is called the Modulo Operator. It returns the remainder of dividing the left-hand operand by right-hand operand. It's used to get the remainder of a division problem.
- If the remainder is not 0, it means that i is odd, and the code inside the if block is executed.
- The print(i) statement is used to print the current odd number i to the console.
#SPJ3
Similar questions