Curriculum
Course: Python-100-Programmes
Login
Text lesson

B-Data Types & Operators-(10 to 21)

B-Data Types & Operators

  1. Input the Length and Breadth of a rectangle and find its Area and perimeter.

Here is a simple Python program to find the area and perimeter of a rectangle:

length = float(input(“Enter length of the rectangle: “))

breadth = float(input(“Enter breadth of the rectangle: “))

 

area = length * breadth

perimeter = 2 * (length + breadth)

 

print(“Area of the rectangle:”, area)

print(“Perimeter of the rectangle:”, perimeter)

 

Example Output:

Enter length of the rectangle: 10

Enter breadth of the rectangle: 5

Area of the rectangle: 50.0

Perimeter of the rectangle: 30.0

 

  1. Input the side of a square and find its Area and perimeter.

 

Here is a simple Python program to find the area and perimeter of a square:

side = float(input(“Enter the side of the square: “))

 

area = side * side

perimeter = 4 * side

 

print(“Area of the square:”, area)

print(“Perimeter of the square:”, perimeter)

 

Example Output:

Enter the side of the square: 6

Area of the square: 36.0

Perimeter of the square: 24.0

 

  1. Input the radius of a circle and find its Area and Perimeter.

Here is a simple Python program to find the area and perimeter (circumference) of a circle:

radius = float(input(“Enter the radius of the circle: “))

 

pi = 3.14

area = pi * radius * radius

perimeter = 2 * pi * radius

 

print(“Area of the circle:”, area)

print(“Perimeter of the circle:”, perimeter)

 

Example Output:

Enter the radius of the circle: 7

Area of the circle: 153.86

Perimeter of the circle: 43.96

  1. Enter the base and height, and find the triangle’s area.

 

Here is a simple Python program to find the area of a triangle:

base = float(input(“Enter the base of the triangle: “))

height = float(input(“Enter the height of the triangle: “))

 

area = 0.5 * base * height

 

print(“Area of the triangle:”, area)

 

Example Output:

Enter the base of the triangle: 10

Enter the height of the triangle: 5

Area of the triangle: 25.0

 

  1. Input a number and find its remainder when divided by 7.

Here is a simple Python program to find the remainder when a number is divided by 7:

num = int(input(“Enter a number: “))

 

remainder = num % 7

 

print(“Remainder when divided by 7:”, remainder)

 

Example Output:

Enter a number: 50

Remainder when divided by 7: 1

 

  1. Input three numbers and find their average.

 

Here is a simple Python program to find the average of three numbers:

a = float(input(“Enter first number: “))

b = float(input(“Enter second number: “))

c = float(input(“Enter third number: “))

 

average = (a + b + c) / 3

 

print(“Average of the three numbers:”, average)

 

Example Output:

Enter first number: 10

Enter second number: 20

Enter third number: 30

Average of the three numbers: 20.0

 

  1. Find simple interest (SI = P × R × T / 100).

Here is a simple Python program to calculate Simple Interest:

p = float(input(“Enter Principal amount (P): “))

r = float(input(“Enter Rate of interest (R): “))

t = float(input(“Enter Time (T): “))

 

si = (p * r * t) / 100

 

print(“Simple Interest =”, si)

 

Example Output:

Enter Principal amount (P): 1000

Enter Rate of interest (R): 5

Enter Time (T): 2

Simple Interest = 100.0

  1. Find compound interest.

Here is a simple Python program to calculate Compound Interest:

p = float(input(“Enter Principal amount (P): “))

r = float(input(“Enter Rate of interest (R) in %: “))

t = float(input(“Enter Time (T) in years: “))

 

# Compound Interest formula: A = P * (1 + R/100)^T, CI = A – P

amount = p * (1 + r/100) ** t

ci = amount – p

 

print(“Compound Interest =”, ci)

print(“Total Amount =”, amount)

 

Example Output:

Enter Principal amount (P): 1000

Enter Rate of interest (R) in %: 5

Enter Time (T) in years: 2

Compound Interest = 102.5

Total Amount = 1102.5

  1. Input the price and discount %, and find the final price.

Here is a simple Python program to calculate the final price after discount:

price = float(input(“Enter the original price: “))

discount = float(input(“Enter discount percentage: “))

 

final_price = price – (price * discount / 100)

 

print(“Final price after discount:”, final_price)

 

Example Output:

Enter the original price: 2000

Enter discount percentage: 10

Final price after discount: 1800.0

  1. Input marks of 5 subjects and find the total and percentage.

Here is a simple Python program to calculate total marks and percentage:

marks1 = float(input(“Enter marks of subject 1: “))

marks2 = float(input(“Enter marks of subject 2: “))

marks3 = float(input(“Enter marks of subject 3: “))

marks4 = float(input(“Enter marks of subject 4: “))

marks5 = float(input(“Enter marks of subject 5: “))

 

total = marks1 + marks2 + marks3 + marks4 + marks5

percentage = (total / 500) * 100  # assuming each subject is out of 100

 

print(“Total marks:”, total)

print(“Percentage:”, percentage, “%”)

 

Example Output:

Enter marks of subject 1: 80

Enter marks of subject 2: 75

Enter marks of subject 3: 90

Enter marks of subject 4: 85

Enter marks of subject 5: 70

Total marks: 400.0

Percentage: 80.0 %

 

  1. Convert hours to minutes and seconds.

Here is a simple Python program to convert hours to minutes and seconds:

hours = float(input(“Enter hours: “))

 

minutes = hours * 60

seconds = hours * 3600

 

print(hours, “hours is equal to”, minutes, “minutes”)

print(hours, “hours is equal to”, seconds, “seconds”)

 

Example Output:

Enter hours: 2

2.0 hours is equal to 120.0 minutes

2.0 hours is equal to 7200.0 seconds

  1. Input principal, rate, time, and calculate EMI.

Here is a simpler version of EMI calculation using Simple Interest (for beginners):

This method is easy for beginners because it avoids compound interest calculations.

Formula:

EMI = (Principal + SI) / Number  of months

 

SI = (P X R X T ) / 100​

 

P = float(input(“Enter principal amount (P): “))

R = float(input(“Enter annual interest rate (R in %): “))

T = float(input(“Enter time in years (T): “))

 

# Calculate simple interest

SI = (P * R * T) / 100

 

# Total amount to pay

total_amount = P + SI

 

# Convert years to months

months = T * 12

 

# EMI

EMI = total_amount / months

 

print(“Monthly EMI =”, EMI)

 

Example Output:

Enter principal amount (P): 100000

Enter annual interest rate (R in %): 10

Enter time in years (T): 2

Monthly EMI = 4583.333333333333

Here is a simple Python program to calculate EMI (Equated Monthly Instalment) using the Compound Interest standard formula:

EMI = ( P × R × (1+R)N  ) / (1+R)N − 1

 

where:

P = Principal loan amount.

R = Monthly interest rate (annual rate ÷ 12 ÷ 100)

N = Number of monthly instalments (time in months)

 

P = float(input(“Enter principal amount (P): “))

R = float(input(“Enter annual interest rate (R in %): “))

T = float(input(“Enter time in years (T): “))

 

# Convert annual rate to monthly and years to months

monthly_rate = R / (12 * 100)

months = T * 12

 

EMI = (P * monthly_rate * (1 + monthly_rate) ** months) / ((1 + monthly_rate) ** months – 1)

 

print(“Monthly EMI =”, EMI)

 

Example Output:

Enter principal amount (P): 100000

Enter annual interest rate (R in %): 10

Enter time in years (T): 2

Monthly EMI = 4614.55

 

Scroll to Top