Program to get all numbers divided by 3 between 1 to 30

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

  1. Use for loop with the range function to iterate over numbers from 1-30.
  2. Using if else statement check whether a  number is divisible by 3 or not.
  3. 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=" ")
    else:
        continue
				
			

Output :

				
					3 6 9 12 15 18 21 24 27 30
				
			

Related Articles

check given number is divided by 3 or not.

assign grades as per total marks.

Program to check if a number is divisible by 3

In this Python if else program we will check if a number is divisible by 3 or not. Print the number divisible by 3.

Divisibility test: The divisibility rule for 3 states that a number is completely divisible by 3 if the sum of its digits is divisible by 3

Steps to solve the programs
  1. Take a number as input through the user.
  2. Check whether that given number is divisible by 3, using an if else statement.
  3. Print the respective output.
				
					num = int(input("Please enter value :"))
if num%3 ==0:
    print("Number is divisible by 3:", num)
else:
    print("Number is not divisible by 3 :", num)
				
			

Output

				
					Please enter value :21
Number is divisible by 3: 21


Please enter value :25
Number is not divisible by 3 : 25
				
			

get all the numbers divided by 3 from 1 to 30.

Related programs

Print the following pattern as shown in ouput.

In this Python Program, we will print the following pattern as shown using Python

Steps to solve the program
				
					char = 97
var1 = 4
var2 = 4

for i1 in range(7):
    if i1 < 4:
        var1 = var1 - 1
        var2 = var2 + 1

        for j1 in range(9):

            if j1 > var1 and j1 < var2:

                print(chr(char), end=" ")
                char += 1
            else:
                print(" ", end=" ")
        print()

        # var1 = var1 - 1
        # var2 = var2 + 1
    else:
        var1 = var1 + 1
        var2 = var2 - 1
        for k in range(9):

            if k > var1 and k < var2:

                print(chr(char), end=" ")
                char += 1
            else:
                print(" ", end=" ")
        print()

				
			

Output :

				
					_________________


        a         
      b c d       
    e f g h i     
  j k l m n o p   
    q r s t u     
      v w x       
        y  
        
_________________
				
			

Print the following pattern

Print the following pattern as shown using Python

In this program, we will print the following pattern using Python.

Steps to solve the program
				
					# Part1 : First will print triangle of numbers in increasing order.
num1 = 65
for i in range(5):
    for j in range(i+1):
        print(chr(num1), end=" ")
        num1 += 1
    print()

# Part2 : Second will print triangle of number is decreasing order.
for k in range(5, 0, -1):
    for l in range(k-1):
        num1 += 1
        print(chr(num1), end=" ")
    print()
				
			

Output :

				
					A 
B C 
D E F 
G H I J 
K L M N O 
Q R S T 
U V W 
X Y 
Z  
				
			

find the maximum number from the list

Print the following pattern

Program to find the maximum number from the list

In this program, we will find the maximum number from the list.

Steps to solve the program
  1. Take a list as input and create a variable to find the maximum number from the list and assign its value equal to 0.
  2. Use for loop to iterate over the list elements.
  3. If an element from the list is greater than the variable that we have created then change the value of the variable by that element.
  4. Print the output.
				
					list1 = [12,14,45,88,63,97,88]
max_ = 0

for i in list1:
    if i > max_:
        max_ = i
        
print("Maximum number: ",max_)
				
			

Output :

				
					Maximum number:  97
				
			

add elements from one list to another list and print It in descending order

Print the following pattern

Add elements from one list to another list

In this program, we will add elements from one list to another list and print It in descending order.

Steps to solve the program
  1. Take a list as input and create another empty list.
  2. Use for loop to iterate over all the elements of the list.
  3. During iteration add elements to the empty list.
  4. Print the list in descending order using sorted().
				
					l1 = [2,5,8,0,1,4]
l2 = []

for ele in l1:
    l2.append(ele)
    
sorted(l2,reverse = True)
				
			

Output :

				
					[8, 5, 4, 2, 1, 0]
				
			

sort a list using for loop

find the maximum number from the list

Program to sort a list using for loop in Python.

In this program, we will sort a list using for loop in Python.

Steps to solve the program
  1. Take a list as input.
  2. Use for loop with range function to iterate over list values.
  3. Use a nested for loop to iterate over a value and remaining values of the list.
  4. If the selected value is greater than any value from the list then assign that element to a variable.
  5. Change the value of the grater value by smaller value and smallervalue by greater value.
  6. Print the output.
				
					l = [6,8,2,3,1,0,5]

for i in range(len(l)):
    for j in range(i,len(l)):
        if l[i]>l[j]:
            temp=l[i]
            l[i]=l[j]
            l[j]=temp
print(l)
				
			

Output :

				
					[0, 1, 2, 3, 5, 6, 8]
				
			

find the total number of special characters in a file

add elements from one list to another list and print It in descending order

Find the total number of special characters

In this program, we will find the total number of special characters in a file.

Steps to solve the program
  1. Create a variable to count the total number of special characters and assign its value equal to 0.
  2. Open the desired file using open() in reading mode.
  3. Use for loop iterate over the data.
  4. If the character is a special character then add 1 to the variable that we have created.
  5. Use isalnum() for this purpose.
  6. Print the output.
				
					f1=open("file1.txt","r")
data=f1.read()

is_special = 0

for char in data:
    if char.isalnum():
        is_special += 1
        
print("NUmber of digits: ",is_special)
				
			

Output :

				
					3
				
			

find the total number of Uppercase letters in a file

sort a list using for loop

Program to find the total number of Uppercase letters

In this program, we will find the total number of Uppercase letters in a file.

Steps to solve the program
  1. Create a variable to count the total number of uppercase letters and assign its value equal to 0.
  2. Open the desired file using open() in reading mode.
  3. Use for loop iterate over the data.
  4. If the character is an Uppercase letter then add 1 to the variable that we have created.
  5. Use isupper() for this purpose.
  6. Print the output.
				
					f1=open("file1.txt","r")
data=f1.read()

is_upper = 0

for char in data:
    if char.isupper():
        is_upper += 1
        
print("NUmber of digits: ",is_upper)
				
			

Output :

				
					2
				
			

find the total number of digits in a file

find the total number of special characters in a file

Find the total number of digits in a file

In this program, we will count the the total number of digits in a file.

Steps to solve the program
  1. Create a variable to count the total number of digits and assign its value equal to 0.
  2. Open the desired file using open() in reading mode.
  3. Use for loop iterate over the data.
  4. If the element is a digit then add 1 to the variable that we have created.
  5. Use isdigit() for this purpose.
  6. Print the output.
				
					f1=open("file1.txt","r")
data=f1.read()

is_digit = 0

for i in data:
    if i.isdigit():
        is_digit+=1
        
print("NUmber of digits: ",is_digit)
				
			

Output :

				
					3
				
			

count the total number of characters in a file

find the total number of Uppercase letters in a file