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

Python Programs

The document provides examples of Python programs to perform basic calculations and accept user input. The programs include: accepting and printing a name and age; calculating the sum of two numbers; building a basic calculator; finding the average of three numbers; calculating the area of a rectangle; and calculating the area of a square. Each question includes the code to write the Python program and print the result.

Uploaded by

Pragati Sharma
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)
45 views

Python Programs

The document provides examples of Python programs to perform basic calculations and accept user input. The programs include: accepting and printing a name and age; calculating the sum of two numbers; building a basic calculator; finding the average of three numbers; calculating the area of a rectangle; and calculating the area of a square. Each question includes the code to write the Python program and print the result.

Uploaded by

Pragati Sharma
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/ 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