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

Week 2

Uploaded by

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

Week 2

Uploaded by

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

Week 2:

1. Python Program to Find the Square Root

n=int(input('enter any number:'))


sn=n**0.5
print('square root of',n,'is',sn)

2. Python Program to Calculate the Area and Perimeter of Triangle and Circle.

s1 = float(input("Enter the first side of the triangle : "))


s2 = float(input("Enter the second side of the triangle : "))
s3 = float(input("Enter the third side of the triangle : "))
p = (s1 + s2 + s3)
s = p/2
area = (s * (s-s1) * (s-s2)*(s-s3))**0.5
print("The perimeter of the triangle is : {0:.2f}".format(p))
print("The area of the triangle is : {0:.2f}".format(area))
PI = 3.14
r = float(input("Enter the radius of a circle:"))
area = PI * r * r
print("Area of a circle = %.2f" %area)
pc=2*PI*r
print('perimeter of circle=%.2f' %pc)

3. Python Program to Solve Quadratic Equation

import cmath
a = float(input('Enter a: '))
b = float(input('Enter b: '))
c = float(input('Enter c: '))

d = (b**2) - (4*a*c)

sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)
print('The solution are {0} and {1}'.format(sol1,sol2))

4. Python Program to Swap Two Variables


P = int( input("Please enter value for P: "))
Q = int( input("Please enter value for Q: "))

temp = P
P=Q
Q = temp

print ("The Value of P after swapping: ", P)


print ("The Value of Q after swapping: ", Q)

5. Python Program to Convert Kilometres to Miles

km=float(input(“enter value In kilometers:”))


#note: 1 km=0.621371mile
conv_fac=0.621371
miles=km*conv_fac
print(“%0.2f kilometers is equal to %0.2f miles” %(km,miles))

6. Python Program to Convert Celsius To Fahrenheit

Celsius=float(input(“enter celsius temperature”))


Fahrenheit=(Celsius*1.8)+32
print(“%0.1f degree clesius is equal to %0.1f degree Fahrenheit” %
(Celsius,Fahrenheit))

You might also like