Python program to print the square of the number

In this python if else program, we will print the square of the number if it is divided by a certain number ( 11 ). To find the square of a number we need to multiply that number by itself or we can use power operator to get square of the value. e.g. var1**2

Hint:
Use ** to get the square.

Steps to solve the program
  1. Take a number as input through the user.
  2. Use an if-else statement to check whether the given number is divisible by 11 or not.
  3. If yes then print its square.
  4. Else print False.
				
					# Take input through the user
num =  int(input("Enter a number: "))
# Check for division
if num%11 == 0:
    # Print output
    print(num**2)
else:
    # Print output
    print("Number is not divisible by 11")
				
			

Output :

				
					Enter a number: 22
484
				
			
				
					Enter a number: 31
Number is not divisible by 11
				
			

Related Articles

check the given number divided by 3 and 5.

check given number is a prime number or not.

Python program to check number is divided by 3 and 5

In this, if else program, we will check whether the given number is divided by 3 and 5 or not. 

Hint:
Use AND(&) with if-else statement.

Steps to solve the program
  1. Take a number as input through the user.
  2. Use if-else statements to check whether the given number is divisible by 3 and 5 also.
  3. If yes then then print True, if not then print False.
				
					# Take input through the user
num =  int(input("Enter a number: "))
# Check for division
if num%3 == 0  and num%5 == 0:
    # Print output
    print("Given number can divide by both 3 and 5")
else:
    # Print output
    print("Given number can not divide by 3 and 5")
				
			

Output : 

				
					Enter a number: 6
Given number can not divide by 3 and 5
				
			
				
					Enter a number: 15
Given number can divide by both 3 and 5
				
			

Related Articles

assign grades as per total marks.

print the square of the number if it is divided by 11.

If-else program to assign grades as per total marks

In this python if else program, we will assign grades to each student as per total marks scored.

Condition for grades:
Marks less than 40: Fail
Marks between 40-50: Grade C
Marks between 51-60: Grade B
Marks between 61-70: Grade A
Marks between 71-80: Grade A+
Marks between 81-90: Grade A++
Marks between 91-100: Excellent

Hint:
Use Multiple if-else statements.

Steps to solve the program
  1. Take marks as input through the user.
  2. Using if-else statements assign grades as per the total marks given.
  3. Use the grades given in the question.
  4. Print the output.
				
					# Take marks through the user
marks = int(input("Enter marks: "))
# Assign grades based on marks
if marks<40:
    # marks is less than 40 then print Fail
    print("Fail")
elif marks>=40 and marks>=50:
    # marks is greater than 40 and less than 50 then got C grade.
    print("Grade C")
elif marks>50 and marks<=60:
    #  marks is greater than 50 and less than 60 then got B grade.
    print("Grade B")
elif marks>60 and marks<=70:
    #  marks is greater than 60 and less than 70 then got A grade.
    print("Grade A")
elif marks>70 and marks<=80:
    #  marks is greater than 70 and less than 80 then got A+ grade.
    print("Grade A+")
elif marks>80 and marks<=90:
    #  marks is greater than 80 and less than 90 then got A++ grade.
    print("Grade A++")
elif marks>90 and marks<=100:
    #  marks is greater than 90 and less than 100 then got Excellent grade.
    print("Excellent")
else:
    # marks is greater than 100 than consider as invalid number..
    print("Invalid marks")
				
			

Output :

				
					Enter marks: 62
Grade C
				
			
				
					Enter marks: 30
Fail
				
			
				
					Enter marks: 93
Excellent
				
			
				
					Enter marks: 100
Invalid marks
				
			

Related Articles

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

check the given number divided by 3 and 5.

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