0% found this document useful (0 votes)
2 views3 pages

Ass 1

The document contains a series of Python programming exercises that cover various topics including calculating the area of a circle, converting Fahrenheit to Celsius, creating a simple calculator, finding square roots, solving quadratic equations, calculating the area of a triangle, formatting strings, displaying personal details, and summing the digits of a five-digit number. Each exercise includes sample code and explanations for the tasks. The programs utilize basic Python concepts such as input, arithmetic operations, conditionals, and functions.

Uploaded by

manasi date
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Ass 1

The document contains a series of Python programming exercises that cover various topics including calculating the area of a circle, converting Fahrenheit to Celsius, creating a simple calculator, finding square roots, solving quadratic equations, calculating the area of a triangle, formatting strings, displaying personal details, and summing the digits of a five-digit number. Each exercise includes sample code and explanations for the tasks. The programs utilize basic Python concepts such as input, arithmetic operations, conditionals, and functions.

Uploaded by

manasi date
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1: Write a Python program which accept the radius of a circle from the user and

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)
***************************************************************************

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
##############Write a Python Program to find the area of triangle
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))
s = (a + b + c) / 2 #semiperimeter
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)##Area of triangle
***************************************************************************
Q7: Write a Python program to print the following string in a specific format
str="Twinkle Twinkle, Little star,\n \
\tHow I wonder what you are!\n\
\t\tUp above the world so high,\n\
\t\tLike a diamond in the sky.\n\
Twinkle Twinkle Little star\n\
\tHow I wonder what you are!";
print(str);

***************************************************************************
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.

print("Name: Manasi Virendra Date.\nAge: 30yrs\nAddress: Pune");

**************************************************************************
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)

You might also like