You are on page 1of 5

Basic Python Programs for practice

Q1.Write a program to enter your name,city,age and print


them.

name=input(“Enter your name:”)


city=input(“Enter your city:”)
age=int(input(“Enter your age:”))
print(“The name is:”,name)
print(“The city is:”,city)
print(“The age of a child is:”,age)

Q2. Write a python program to accept two variable and


use all basic arithmetic operations.

a=int(input(“Enter the first variable value:”))


b=int(input(“Enter the second variable value:”))
print (“The sum of two variables is :”,a+b)
print (“The difference of two variables is :”,a-b)
print (“The product of two variables is :”,a*b)
print (“The quotient of two variables is :”,a/b)
print (“The floor division of two variables is :”,a//b)
print (“The remainder of two variables is :”,a%b)
print (“The exponention of two variables is :”,a**b)

Q3.Write a program to accept radius of a circle and find its area and
circumference of circle.(given area of
circle:3.14*r*r and circumference is: 2*3.14*r) where r is the radius
of a circle.

r=int(input(“Enter radius of circle:”))


area=3.14*r*r
cur=2*3.14*r
print (“Area of given circle is :”,area)
print (“circumference of given circle is :”,cur)

Q4.Write a program to accept the length and breadth of a rectangle


and find its area and perimeter.
(given area of rectangle is length* breadth and perimeter is
2*(length+breadth) )

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


y=int(input(“Enter breadth of rectangle:”))
area=x*y
peri=2*(x+y)
print (“Area of given rectangle is :”,area)
print (“perimeter of given rectangle is :”,peri)

Q5.Write a program to accept three random numbers and find their


average.

a=int(input(“Enter the first variable value:”))


b=int(input(“Enter the second variable value:”))
c=int(input(“Enter the third variable value:”))
d=a+b+c/3
print (“Average of three numbers is:”,d)

Q6. Write a program find simple interest,when principal amount,rate


and time are accepted by the user.(given formula for simple
interest: si=p*r*t/100).

p=eval(input("enter principal amount"))


r=eval(input("enter rate"))
t=eval(input("time"))
si=p*r*t/100
print("simple interest->",si)

Q7.Write a program to swap two numbers.


x=int(input("enter your first number:"))
y=int(input("enter your last second:"))
print("values of x and y before swapping: ", x ," ", y)
x,y = y,x
print("values of x and y after swapping;", x ," ",y)

Q8.Write a program to find area and perimeter of square


(given side of square is accepted by the user)
side=int(input(“Enter side of square:”))
area=side**2
peri=4*side
print (“Area of given square is :”,area)
print (“perimeter of given square is :”,peri)

Q9. Write a program to calculate total amount to after 5%


discount on the total purchase of stationery.

amt=eval(input("enter total purchase amount of stationery"))


dis=amt*5/100
totalamt = amt-dis
print("calculated amount of stationery after discount=",totalamt)

Q10.Write a program to convert miles into kilometers.(given


formula: 1 mile= 1.6 km)
m=eval(input("enter distance in miles"))
km=m*1.6
print("calculated distance in kilometers=",km)

Q11.Write a program to enter marks of 5 subjects of a student and


find total marks and percentage.
m=eval(input("Enter marks of maths:"))
eng=eval(input("Enter marks of eng:"))
h=eval(input("Enter marks of hindi:"))
s=eval(input("Enter marks of social:"))
i=eval(input("Enter marks of ict:"))
t=m+eng+h+s+i
per=t/500*100
print("total marks obtained by student:",t)
print("percentage scored by him/her:",per)

You might also like