Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
Set-1
1. A program that converts temperatures from Fahrenheit to Celsius and vice versa.
• Code :
f=float(input("Enter Fahrenhit temperature:\n"))
c=(5/9)*(f-32)
print("Celsius:",round(c,2))
• Output :
1
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
2. A program that calculates the area and perimeter of a rectangle.
• Code :
l=float(input("Enter length:"))
b=float(input("Enter breadth:"))
print("Perimeter of rectangle is:",round(2*(l+b),2))
print("Area of rectangle is:",round(l*b,2))
• Output :
2
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
3. A program that generates a random password of a specified length.
• Code :
import random
import string
length=int(input("Input the desired length of your password:"))
def generate(length):
a=string.ascii_letters + string.digits + string.punctuation
password = ' '.join(random.choice(a) for i in range(length))
return password
password = generate(length)
print(f"Generated password is: {password}")
• Output :
3
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
4. A program that calculates the average of a list of numbers.
• Code :
n=int(input())
L1=[]
sum=0
for i in range(n):
k=int(input())
L1.append(k)
sum=sum+k
print(sum/n)
• Output:
4
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
5. A program that checks if a given year is a leap year.
• Code :
year=int(input("Enter year"))
if year%400==0 and year%100==0:
print("This year is leap year")
elif year%4==0 and year%100!=0:
print("This year is leap year")
else :
print("This year is not leap year")
• Output :
5
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
6. A program that calculates the factorial of a number.
• Code :
n = int(input("Enter number:"))
fact = 1 for i in
range(1, n+1):
fact = fact * i
print(f"The factorial of {n} is : ", end="")
print(fact)
• Output :
6
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
7. A program that checks if a given string is a palindrome.
• Code :
def pallendrom():
n=int(input())
rem=0
rev=0
temp=n
while n>0:
rem=n%10
rev=rem+(rev*10)
n=n//10
if rev==temp:
print("pallendrom")
else:
print("not pallendrom")
pallendrom()
• Output :
7
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
8. A program that sorts a list of numbers in ascending or descending order.
• Code :
n=int(input("Enter numder of element"))
L1=[]
for i in range(n):
k=int(input())
L1.append(k)
L1=sorted(L1)
print(f"Ascending order:{L1}")
print(f"Deascending order:{L1[::-1]}")
• Output :
8
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
9. A program that generates a multiplication table for a given number.
• Code :
n=int(input("Enter a number:"))
print(f"Table of {n}:")
for i in range(1,11):
print(n, "x",i, "=",i*n)
• Output :
9
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28
Parul Institute of Engineering and Technology
B.Tech. (CE) 4th Sem
303105257 - Programing in Python with Full Stack
Development
10. A program that converts a given number from one base to another.
• Code :
n = input("Enter the value to convert: ")
Fb = int(input("Enter the base value from which you want to convert: "))
tb = int(input("Enter the base value to which you want to convert (2, 8, 10, or 16):
"))
Dv = int(str(n), Fb)
if tb == 16:
Cv = format(Dv, 'X')
else:
Cv = format(Dv, 'b' if tb == 2 else '' if tb == 10 else oct(Dv)
print(Cv)
• Output :
10
NAME: TWISHA HINSU
ENROLLMENT NO: 2203031280003
CLASS: 4B28