Ass 1
Ass 1
compute
the area.
Sample Output :
r = 1.1
Area = 3.8013271108436504
################### Area of Circle################
import math;
radius=float(input("Enter your Radius"));
AreaOfCircle=math.pi*radius*radius;
print("Area of Circle is: ",AreaOfCircle);
*********************************************************
Q2: Temperature of a city in Fahrenheit degrees is input through the keyboard.
Write a
program to convert this temperature into Centigrade degrees.
####temperature in fahrenheit as a Input from User
temperature = float(input("Please enter temperature in fahrenheit:"))
celsius = float((temperature - 32) * 5 / 9)
print("Temperature in celsius: %.2f" %celsius)
**********************************************
Q3: Write a Python Program to make a simple calculator that can add, subtract,
multiply and divide
print("Please select operation -\n" \
"1. Add\n" \
"2. Subtract\n" \
"3. Multiply\n" \
"4. Divide\n")
############Input from User############
select = int(input("Select operations form 1, 2, 3, 4 :"))
number_1 = int(input("Enter first number: "))
number_2 = int(input("Enter second number: "))
########Adition##################
if select == 1:
print("********Addition********\n",number_1+number_2)
elif select == 2:
print("********Subtraction************\n", number_1, "-", number_2,
"=",number_1-number_2)
elif select == 3:
print("********Multiplication*********\n ",number_1, "*", number_2,
"=",number_1*number_2)
elif select == 4:
print("***********Division**********\n",number_1, "/", number_2,
"=",number_1/number_2)
else: print("Invalid ")
***************************************************************************
Q4: Write a Python Program to calculate the square root
num=16
num_sqrt = num * 0.5
print('The square root of %d is %d'%(num ,num_sqrt));
***************************************************************************
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
[Hint: import complex math module - import cmath]
a = int(input("Enter the coefficients of a: "))
b = int(input("Enter the coefficients of b: "))
c = int(input("Enter the coefficients of c: "))
d = b**2-4*a*c # discriminant
if d < 0:
print ("This equation has no real solution")
elif d == 0:
x = (-b+math.sqrt(b**2-4*a*c))/2*a
print ("This equation has one solutions: "), x
else:
x1 = (-b+math.sqrt((b**2)-(4*(a*c))))/(2*a)
x2 = (-b-math.sqrt((b**2)-(4*(a*c))))/(2*a)
print ("This equation has two solutions: ", x1, " or", x2)
***************************************************************************
***************************************************************************
Q8: Write a Python program to display your details like name, age, address in three
different lines.
######Write a Python program to display your details like name, age, address in
three different lines.
**************************************************************************
Q9: 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 �%�)
num=int(input("Enter the five digits Number :"))
sum=0
a=num%10
n=num//10
sum=sum+a
a=n%10
n=n//10
sum=sum+a
a=n%10
n=n//10
sum=sum+a
a=n%10
n=n//10
sum=sum+a
a=n%10
sum=sum+a;
print("sum of the Digits = ",sum)