LAB1 :PYTHON
INPUT
# Q1: Write a Python program which accept the radius
of a circle from the user and compute the area.
import math
r= int(input("radius of circle"))
A = math.pi*(r)**2
print("Area of circle = ", A)
OUTPUT:
radius of circle7
Area of circle = 153.93804002589985
Q2
#Q2Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a
#program to convert this temperature into Centigrade degrees.
import math
x= int(input("Temprature of the city (in farenhit):"))
y= (x-32)/1.8
print ("temparature in degree celcius :", y , math.degrees )
OUTPUT:
Temprature of the city (in farenhit):70
temparature in degree celcius : 21.11111111111111 <built-in function degrees>
Q3:
#Q3: Write a Python Program to make a simple calculator that can add, subtract, multiply and divide
print("TO ADD")
x= int(input("Enter first number:"))
y= int(input("Enter second number:"))
x+y
print ("addition of two numbers: x+y=", x+y)
print("TO SUBSTRACT")
a= int(input("Enter first number:"))
b= int(input("Enter second number:"))
a-b
print ("substraction of two numbers: a-b=", a-b)
print("TO MULTIPLY")
c= int(input("Enter first number:"))
d= int(input("Enter second number:"))
c*d
print ("multiplication of two numbers: c*d=", c*d)
print("TO DEVIDE")
m= int(input("Enter first number:"))
n= int(input("Enter second number:"))
m/n
print ("division of two numbers: m/n=", m/n)
OUTPUT:
TO ADD
Enter first number:5
Enter second number:6
addition of two numbers: x+y= 11
TO SUBSTRACT
Enter first number:56
Enter second number:45
substraction of two numbers: a-b= 11
TO MULTIPLY
Enter first number:56
Enter second number:7
multiplication of two numbers: c*d= 392
TO DEVIDE
Enter first number:64
Enter second number:8
division of two numbers: m/n= 8.0
Q4:
#Q4: Write a Python Program to calculate the square root
import math
y= int (input("enter number"))
x= math.sqrt(y)
print(x)
OUTPUT:
enter number25
5.0
Q5:
#Q5: Write a Python Program to Solve the quadratic equation ax**2 + bx + c = 0
# Coeffients a, b and c are provided by the user
a= int(input("a="))
b= int(input("b="))
c= int(input("c="))
#to calculate delta
d=(b**2)-(4*a*c)
import math
#Solution
x1=(-b- math.sqrt(d))/(2*a)
x2=(-b+ math.sqrt(d))/(2*a)
print("solution are",x1,x2)
OUTPUT:
a=1
b=5
c=6
solution are -3.0 -2.0
Q6:
#Q6: Write a Python Program to find the area of triangle
# Three sides of the triangle a, b and c are provided by the user
a= int(input("a="))
b= int(input("b="))
c= int(input("c="))
s=(1/2)*(a+b+c)
import math
A=math.sqrt(s*(s-a)*(s-b)*(s-c))
print("Area of triangle =", A )
OUTPUT:
a=4
b=6
c=8
Area of triangle = 11.61895003862225
Q7:
#Q7: If a five-digit number is input through the keyboard, write a program to calculate the sum
#of its digits without using any loop. (Hint: Use the modulus operator ‘%
sum=0
n= int(input("num="))
x1= n%10
sum=sum+x1
n= n//10
x2= n%10
sum=sum+x2
n= n//10
x3= n%10
sum=sum+x3
n= n//10
x4= n%10
sum=sum+x4
n= n//10
x5= n%10
sum=sum+x5
print("Addition of number=",sum)
OUTPUT:
num=12345
Addition of number= 15
#Q8: Write a Python program to print the following string in a specific format
print(" Twinkle, twinkle, little star,\n\
How I wonder what you are!\n\
Up above the world so high,\n\
Like a dimond in the sky.\n\
Twinkle, twinkle, little star,\n\
How i wonder what you are!")
OUTPUT:
Twinkle, twinkle, little star,
How I wonder what you are!
Up above the world so high,
Like a dimond in the sky.
Twinkle, twinkle, little star,
How i wonder what you are!
Q9:
#Q9:Write a Python program to display your details like name, age, address in three different lines.
print( "Name: Pranjali Balasaheb Alure\n\
Age:22\n\
Address: At.post Mahapur, latur, Maharastra, India.")
OUTPUT:
Name: Pranjali Balasaheb Alure
Age:22
Address: At.post Mahapur, latur, Maharastra, India.