PYTHON LAB ASSIGNMENT:
Program1.Write a program that asks the user for his/her
name and welcome him/her.
name=input("What is your name?")
print("welcome", name)
OUTPUT:
Program2.Write a program that accepts principle, rate,
time from the user and print the simple interest.
principle=float(input("Enter the principle amount"))
rate=float(input("Enter rate"))
time=float(input("Enter time in years"))
Interest=(principle*rate*time)/100
print("Simple interest",Interest)
OUTPUT:
Program3.Write a program that prompts the user to input
principle, rate and time and calculate compound interest.
principle=float(input("Enter the principle amount"))
rate=float(input("Enter rate"))
time=float(input("Enter time in years"))
r=rate/100
amount=principle*(1+r)**time
Compound_interest=amount-principle
print("The compound interest is",Compound_interest)
OUTPUT:
Program4.Write a program to calculate the area and
perimeter of various polygons such as triangle, rectangle, and
circle.
##Area and perimeter of triangle
import math
a=float(input("Enter side a"))
b=float(input("Enter side b"))
c=float(input("Enter side c"))
perimeter=a+b+c
##Using Heron's formula to calculate area
s=perimeter/2
area=math.sqrt(s*(s-a)*(s-b)*(s-c))
print("The area of triangle is",area)
print("The perimeter of triangle", perimeter)
OUTPUT:
##Area and perimeter of rectangle
L=float(input("Enter lenght of rectangle"))
B=float(input("Enter breadth of rectangle"))
area=L*B
perimeter=2*(L+B)
print("The area of rectangle is",area)
print("The perimeter of rectangle", perimeter)
OUTPUT:
##Area and circumference of cicle
R=float(input("Enter radius of circle"))
area=3.14*R**2
circumference=2*3.14*R
print("The area of circle is",area)
print("The perimeter of circle",circumference )
OUTPUT:
Program5.Write a program to input three number separated
by comma and find the largest and smallest number among
them.
numbers=input("Enter three numbers")
a,b,c=map(int,numbers.split(','))
largest=max(a,b,c)
smallest=min(a,b,c)
print("The largest number is",largest)
print("The smallest number is",smallest)
OUTPUT:
Program6.Write a program to find the root of a quadratic
equation using python.
##General form of quadratic equation
##ax^2+bx+c=0
import math
a=float(input("Enter coefficient a:"))
b=float(input("Enter coefficient b:"))
c=float(input("Enter coefficient c:"))
D=b**2-4*a*c
if D>0:
root1=(-b+math.sqrt(D))/2*a
root2=(-b-math.sqrt(D))/2*a
print("Two real and distinct roots are",root1,root2)
elif D==0:
root=-b/(2*a)
print("Two real and equal roots are",root)
elif D<0:
print("no real roots are possible")
OUTPUT:
Program7.Write a program to print all prime numbers inside
a range of numbers provided by user.
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
# Get range from the user
start = int(input("Enter the start of the range: "))
end = int(input("Enter the end of the range: "))
print(f"Prime numbers between {start} and {end} are:")
# Loop through the range and print primes
for num in range(start, end + 1):
if is_prime(num):
print(num, end=' ')
OUTPUT: