Programs
Programs
Please note: - Certificate, Index Page will be given during the class by subject teacher, hence
don’t fill that.
1. Calculate the total and Percentage of 5 Students using mathematical formula.
2. Write a python program to input the temperature in Fahrenheit and convert the temperature from Fahrenheit to
Celsius. [Formula is C= ((F-32) * 5)/9]
fah=float(input("Enter the temperature in Faherenheit:"))
print("The temperature in Faherenheit is:",fah)
Celsius= ((fah-32)*5)/9
print("The equivalent temperature in Celsius is",Celsius)
3. Write a python program to calculate the area of the circle using math module.
[Formula :- Area=pi*r*r]
import math
radius=int(input("Enter the radius of the circle:"))
area= math.pi*radius*raduis
print("The area of the circle is:",area)
import math
radius=float(input("Enter the radius of a sphere:"))
Volume=(4/3)*math.pi*radius*radius*radius
print("The volume of the sphere is:",Volume)
5. Write a python program to input the marks and calculate the total and percentage. Give the appropriate grade to
the student based on the following.(Use conditional statements).
Range Grade
90-100 A
89-75 B
74-60 C
59-40 D
Below 39 Fail
6. Write a python program to input three numbers and calculate the largest of three numbers.
Output:
a) * b) A c) 1 2 3 4 5
* * A B 1 2 3 4
* * * A B C 1 2 3
* * * * A B C D 1 2
* * * * * A B C D E 1
a.
for i in range(0,5):
num=65
for j in range(0,i+1):
ch=chr(num)
print(ch,end=" ")
num=num+1
print()
9 (A) Write a python program to input a number and check whether the given number is Armstrong
number or not. 15/10/2022
[Armstrong number is a number where sums of cubes are equal to number itself.
Eg: 153 is an Armstrong number where 13+53+33= 153]
num=int(input("Enter any number:"))
tot=0
temp=num
while temp>0:
dig=temp%10
tot+=dig**3
temp//=10
if num==tot:
print(num,"is an armstrong number")
else:
print(num,"is not armstrong number")
9(B) Write a python program to input a number and check whether the given number is palindrome or
not. 15/10/2022
[A palindrome number is a number that is same after reverse.
Eg:121=121]
if( temp==rev):
print("the number is palindrome")
else:
print("the number is not palindrome")
12. Write a python program to input a list of elements and search for a given element in the list.
22/10/2022
list1=eval(input("Enter a List:"))
length=len(list1)
element=int(input("enter a element to be searched for:"))
for i in range (0,length-1):
if element==list1[i]:
print(element,"found at index:",i)
break
else:
print(element,"not found in the given list")
13. Write a python program to find the minimum element from a list of element along with its index in
the list. 22/10/2022
lst=eval(input("Enter the elements of the list:"))
length=len(lst)
min_ele=lst[0]
min_index=0
for i in range(1,length):
if lst[i]< min_ele :
min_ele=lst[i]
min_index=i
print("Given list is:",lst)
print("The minimum element of the given list is :")
print(min_ele,"at index",min_index)
14. Write a program to input names of n students and store them in a tuple. Also, input a name from
the user and find if this student is present in the tuple or not. 02/11/2022
lst=[]
n=int(input("How many students?"))
for i in range(1,n+1):
name=input("Enter the name of the studemt " +str(i) + ": ")
lst.append(name)
ntuple=tuple(lst)
nm=input("Enter the name to be searched for:")
if nm in ntuple:
print(nm, "exists in the tuple")
else:
print(nm,"does not exist in the tuple")
17. Write a python program to create an empty dictionary for creating world database. 05/11/2022
countryDb={}
#infinite loop
while True:
#print menu
print("1. Insert")
print("2. Display all countries")
print("3. Display all capitals")
print("4. Get capital")
print("5. Delete")
#get user choice
choice=int(input("Enter your choice(1-5)"))
#if insert
if choice==1:
country=input("Enter country :").upper()
capital=input("Enter capital :").upper()
countryDb[country]=capital
#to display all countries
elif choice==2:
print(list(countryDb.keys()))
#to display all capitals
elif choice==3:
print(list(countryDb.values()))
#to display capital of a specific country
elif choice==4:
country=input("Enter country").upper()
print(countryDb[country])
#to delete entry of a specific country
elif choice==5:
country=input("Enter country :").upper()
del countryDb[country]
#if none of the above option
else:
break
18. Write a python program to create empty dictionary for the game Rock, paper and scissor.
09/11/2022
import random
roundNo=1 #intialize print("You scores")
#create a dictionary of options elif cChoice==1 and myChoice==3:
options={1:"Rock", 2:"Paper",3:"Scissor"} cScore+=1
#declare variables for maintaining score print("Computer scores")
myScore=0 #keeps track of my score elif cChoice==2 and myChoice==1:
cScore=0 #keeps track of computer score cScore+=1
tie=0 #keeps track of no. of ties print("Computer scores")
#Play the game for 10 rounds elif cChoice==3 and myChoice==2:
while roundNo<=10: cScore+=1
#print the round no print("Computer scores")
print() #print current score tally
print("ROUND : ",roundNo) print("Your Score :",myScore)
#get user choice, from the choices available print("Computer Score :",cScore)
print("1 Rock") print("Tied :",tie)
print("2 Paper")
print("3 Scissor") #increment the current round
myChoice=int(input("Enter your choice(1-3)")) roundNo+=1
print("You chose :",options[myChoice])
#get computer choice #compute the winner
cChoice=random.randint(1,3) print()
print("Computer chose :",options[cChoice]) if myScore>cScore:
#update score print("Congratulations!! you won")
if myChoice==cChoice: elif cScore>myScore:
tie+=1 print("Computer won..try again")
print("Tie") else:
elif myChoice==1 and cChoice==3: print("Game ends in a tie")
myScore+=1
print("You scores")
elif myChoice==2 and cChoice==1:
myScore+=1
print("You scores")
elif myChoice==3 and cChoice==2:
myScore+=1
19. Write a program to input the value of x and n and print the sum of the following series:
12/11/2022
1+x1+x2+x3+x4+. .......... xn
import math
n=int(input("Enter the number of terms:"))
x=int(input("Enter the value of x:"))
total=1
power=1
for i in range(1,n):
total+=math.pow(x,power)
power=power+1
print("The sum of the series is:",total)