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

Assignment 1

python program

Uploaded by

kaurmultani222
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment 1

python program

Uploaded by

kaurmultani222
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Assignment 1

1. Program that asks the user to input


two numbers and then prints their sum.

a=input("Enter first num:")


b=input("Enter second num:")
sum=int(a)+int(b)
print(sum)

OUTPUT:

2. Program that calculates the area of a


circle given its radius. Use the formula:
Area=pi*r*r
R=int(input("Enter the value of R: "))
area=3.14*(R*R)
print("Area of circle: ", area)

3. Program to compute simple interest. Use


the formula:
Simple Interest=P*R*T/100
Where:
P=Principal
R=Rate of interest
T=Time

p=float(input("enter principal amount: "))


r=float(input("enter percent of rate: "))
t=float(input("enter time: "))
SI= p*r*t/100
print("Simple Interest is: ", SI)
4. Program to convert temperatures from
Celsius to Fahrenheit. Use the formuls:
F=(C*9/5)+32

C=float(input("Enter the
Temperature in celsius: "))
F=(C*9/5)+32
print("The temparature in Fahrenheit
is:", F)
5. Program that asks the user to input a
number and determines whether it is
even or odd
num=int(input("Enter any number:"))
if (num%2)==0:
print("The number is even")
else:
print("The number is odd")
6. Program that swaps the values of two
variables without using a third variable.

x=int(input("Enter the first number: "))


y=int(input("Enter the second number:
"))
print("Before swapping: x=", x, "y=", y)
x,y=y,x
print("After swapping: x=", x, "y=", y)
7. Program that calculates the Body Mass
Index(BMI). Use the formula:
BMI= weight(kg)/height(m^2)

weight=float(input("Enter your weight in


kilograms: "))
height=float(input("Enter your height in
meters: "))
bmi=weight/(height**2)
print("Your BMI is: ", bmi)
8. Program that solves a quadratic
equation. The quadratic equation is
given by: ax^2+bx+c=0
Use the quadratic formula: −𝑏 ± √𝑏 ^2 −
4𝑎𝑐 /2a

import cmath
a=float(input("Enter the coefficient of a:
"))
b=float(input("Enter the coefficient of b:
"))
c=float(input("Enter the coefficient of c:
"))
d=(b**2)-(4*a*c)
sol1=(-b-cmath.sqrt(d))/(2*a)
sol2=(-b+cmath.sqrt(d))/(2*a)
print('The solutions are {0} and
{1}'.format(sol1,sol2))

You might also like