You are on page 1of 2

PYTHON PROGRAMS

Q1) Write a python program to accept name and age from the user and print it.

Ans) name=input(“Enter your name:”)

age=input(“Enter your age:”)

print(name)

print(age)

Q2) Write a python program to print the sum of 2 numbers using int() function.

Ans) num1=int(input(“Enter first number:”))

num2=int(input(“Enter second number:”))

sum=num1+num2

print(sum)

Q3) Write a python program to create a simple calculator (doing plus,minus,multiply and
divide) on 2 numbers.

Ans) num1=int(input(“Enter first number:”))

num2=int(input(“Enter second number:”))

sum=num1+num2

subtract=num1-num2

product=num1*num2

division=num1/num2

print(“Addition of 2 numbers =“,sum)

print(“Subtraction of 2 numbers=”,subtract)

print(“Product of 2 numbers =”,product)

print(“Division of 2 numbers :”,division)


Q4) Write a python program to find the average of 3 numbers

Ans) num1=int(input(“Enter first number:”))

num2=int(input(“Enter second number:”))

add=num1+num2+num3

avg=add/3

print(“Addition of 2 numbers = ”,add)

print(“average of 2 numbers = ”,avg)

Q5) Write a python program to calculate area of a rectangle

Ans) length=int(input(“Enter the length of rectangle:”))

width=int(input(“Enter the width of rectangle”))

area=length*width

print(“Area of rectangle=”, area)

Q5) Write a python program to calculate area of a square

Ans) side=int(input(“Enter the side of square:”))

area=side*side

print(“Area of square=”, area)

You might also like