0% found this document useful (0 votes)
10 views

Python Programs ref.to exam(1)

The document contains various Python programs demonstrating basic programming concepts. These include calculating the area and perimeter of a rectangle, finding simple interest, checking if a number is even or odd, determining the largest of three numbers, printing student grades based on average marks, calculating the sum and average of three numbers, reversing a number, and displaying multiplication tables. Each program is presented with input prompts and output statements.

Uploaded by

bthejalnaidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Programs ref.to exam(1)

The document contains various Python programs demonstrating basic programming concepts. These include calculating the area and perimeter of a rectangle, finding simple interest, checking if a number is even or odd, determining the largest of three numbers, printing student grades based on average marks, calculating the sum and average of three numbers, reversing a number, and displaying multiplication tables. Each program is presented with input prompts and output statements.

Uploaded by

bthejalnaidu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Programs

● Program to find area and perimeter of rectangle

l=int(input("Length : "))
w=int(input("Width : "))
area=l*w
perimeter=2*(l+w)
print("Area of Rectangle : ",area)
print("Perimeter of Rectangle : ",perimeter)

● Program to find simple interest

simple_interest(p,t,r):
print('The principal is', p)
print('The time period is', t)
print('The rate of interest is',r)
si = (p * t * r)/100
print('The Simple Interest is', si)
return si
simple_interest(8, 6, 8)

● Program to check if the input number is even or odd

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


if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))

● Python Program find the largest number among three numbers using if-else

# Input three numbers


num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
# Compare numbers using if-else
if num1 >= num2 and num1 >= num3:
largest = num1
elif num2 >= num1 and num2 >= num3:
largest = num2
else:
largest = num3
print("The largest number is:", largest)

● Python Program to print grade of a student based on percentage using if elif else ladder
after inputting marks in 5 subjects
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")

● Program to find Sum and Average of three numbers


a=int(input("Enter the 1st number: "))
b=int(input("Enter the 2nd number: "))
c=int(input("Enter the 3rd number: "))
sum=a+b+c
avg=sum/3
print("Sum of all 3 numbers is: ",sum)
print("Average of all 3 numbers is: ",avg)

● Program to reverse a number


num = 1234
reversed_num = 0
while num != 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
print("Reversed Number: " + str(reversed_num))

● Python program to print the multiplication table of a given number using a loop:
num = int(input("Enter a number to print its multiplication table: "))
print(f"Multiplication table of {num}:")
for i in range(1, 11):
print(f"{num} * {i} = {num * i}")

● Python Program to display the multiplication table


num = int(input("Display multiplication table of? "))
for i in range(1, 11):
print(num, 'x', i, '=', num*i)

You might also like