In this Python if else program we will get all numbers within a given range divided by a certain number. It will print all the numbers which are divisible by 3 between 1-30
Hint:
Use for loop with the range function
Steps to solve the program
- Use for loop with the range function to iterate over numbers from 1-30.
- Using if else statement check whether a number is divisible by 3 or not.
- If it is divisible by 3 then print the number.
# Iterate over numbers from 1-30
for i in range(1,31):
# Check whether number is divisible by 3
if i%3 == 0:
# Print output
print(i,end=" ")
Output :
3 6 9 12 15 18 21 24 27 30
Related Articles
If else program to assign grades as per total marks.
Python program to check the given number divided by 3 and 5.
Python program to print the square of the number if it is divided by 11.
Python program to check given number is a prime number or not.
Python program to check given number is odd or even.
Python program to check a given number is part of the Fibonacci series from 1 to 10.