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

Programs

The document provides examples of Python programs to be completed as part of a Grade XI Computer Science lab program. It includes 6 programs that calculate totals, percentages, temperatures, areas of shapes using formulas, and find the largest of three numbers. It also includes pending programs 7-20 that cover additional concepts like patterns, Armstrong and palindrome numbers, string analysis, searching lists, minimum elements, tuples, and dictionaries. The student is to write the code, run the programs, and record the outputs for each example.

Uploaded by

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

Programs

The document provides examples of Python programs to be completed as part of a Grade XI Computer Science lab program. It includes 6 programs that calculate totals, percentages, temperatures, areas of shapes using formulas, and find the largest of three numbers. It also includes pending programs 7-20 that cover additional concepts like patterns, Armstrong and palindrome numbers, string analysis, searching lists, minimum elements, tuples, and dictionaries. The student is to write the code, run the programs, and record the outputs for each example.

Uploaded by

Anagha Avinash
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lab Programs Grade XI Computer Science

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.

phy=int(input("Enter the marks of physics:"))


chem=int(input("Enter the marks of chemistry:"))
Math=int(input("Enter the marks of Math:"))
Comp=int(input("Enter the marks of Computers:"))
Eco=int(input("Enter the marks of Economics:"))
Total=phy+chem+Math+Comp+Eco
Percentage= (Total/500) *100
print("Grand total is:",Total)
print("Percentage is:", Percentage)

Output to be written on blank page [left side]:


Enter the marks of physics:80
Enter the marks of chemistry:70
Enter the marks of Math:60
Enter the marks of Computers:80
Enter the marks of Economics:70

Grand total is: 360


Percentage is: 72.0

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)

Output to be written on blank page [left side]:


Enter the temperature in Faherenheit:98
The temperature in Faherenheit is: 98.0
The equivalent temperature in Celsius is 36.666666666666664

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)

Output to be written on blank page [left side]:


Enter the radius of the circle: 5
The area of the circle is: 78.53981633974483
4. Write a python program to calculate the volume of the Sphere using math module.
[Formula Volume of Sphere=4/3 π r3 ]

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)

Output to be written on blank page [left side]:


Enter the radius of a sphere: 5
The volume of the sphere is: 523.5987755982989

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

phy=int(input("Enter the marks of physics:"))


chem=int(input("Enter the marks of chemistry:"))
Math=int(input("Enter the marks of Math:"))
Comp=int(input("Enter the marks of Computers:"))
Eco=int(input("Enter the marks of Economics:"))
Total=phy+chem+Math+Comp+Eco
Percentage= (Total/500) *100
average=Total/5
print("Grand total is:",Total)
print("Perncentage is:",Percentage)
if average >= 90 and average<=100:
grade = 'A'
elif average >= 80 and average < 90:
grade = 'B'
elif average >= 70 and average < 80:
grade = 'C'
elif average >= 60 and average < 70:
grade = 'D'
else:
grade = 'FAIL'
print('The average is:',average)
print('The grade is:',grade)

Output to be written on blank page [left side]:


Enter the marks of physics:80
Enter the marks of chemistry:75
Enter the marks of Math:65
Enter the marks of Computers:80
Enter the marks of Economics:80
Grand total is: 380
Perncentage is: 76.0
The average is: 76.0
The grade is: C

6. Write a python program to input three numbers and calculate the largest of three numbers.

n1=float(input("Enter the first number:"))


n2=float(input("Enter the second number:"))
n3=float(input("Enter the third number:"))
if (n1>n2 and n1>n3):
print(" largest number is:",n1)
elif (n2>n3 and n2>n1):
print("The largest number is:",n2)
else:
print("The largest number is:",n3)

Output:

Enter the first number:1.0


Enter the second number:2.0
Enter the third number:3.0
The largest number is: 3.0

7. Write a python program to calculate the factorial of the given number.


[ Eg: Factorial Number of 5 is 5*4*3*2*1=120]

i=int(input("Enter the number:"))


fac=1
while(i>0):
fac=fac*i
i=i-1
print("Factorial of thr given number is:",fac)

Output to be written on blank page [left side]:

Enter the number:5


Factorial of the given number is: 120
Pending Lab Programs 8-20
 Mention the dates mentioned here as date of experiment.
 Outputs will be written when we execute the programs in lab class.

8. Write a python program to generate the following patterns: 12/10/2022

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):


for j in range(0,i+1):
print( " *" , end= " ")
print()
b.

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()

c. n=int(input("Enter the number of rows needed:"))


for i in range(n):
for j in range(0,5-i):
print(j+1,end=" ")
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]

n=int(input("Enter any number:"))


temp=n
rev=0
while n>0:
dig=n%10
rev=rev*10 +dig
n=n//10

if( temp==rev):
print("the number is palindrome")
else:
print("the number is not palindrome")

10. Write a python program to input a string and count 19/10/2022


(a) number of vowels,
(b) number of consonants
(c) number of lowercase
(d) number of uppercase
letters of the given string.
str=input("Enter the string:")
vc=cc=0
lc=uc=0
for i in range(0,len(str)):
if (str[i] in ('a','e','i','o','u')):
vc=vc+1
elif (str[i] >= 'a' and str[i]<='z'):
cc=cc+1
print("Number of vowels are:",vc)
print("Number of consonants are:",cc)
for a in str:
if a.islower():
lc=lc+1
elif a.isupper():
uc=uc+1
print("Number of lowercase letters are :",lc)
print("Number of uppercase letters are:",uc)

11. Write a python program to input a string and count 19/10/2022


(a) number of special characters,
(b) number of digits
(c) number of spaces
of the given string.

a=input("Enter a sentence having alphabets and numbers:")


print("The Sentence is:",a)
special="!@#$%^&*()':;<>,.?/"
digit_count=0
s_count=0
sp_count=0
for char in a:
if char.isdigit():
digit_count+=1
elif char in special:
sp_count+=1
elif char.isspace():
s_count+=1
print("No of Digits:",digit_count)
print("No of Space:",s_count)
print("No of Special Characters:",sp_count)

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")

15.Create the following tuples using a for loop. 02/11/2022


(a)- A tuple containing the square of the integers 1 to 50
l=list()
for a in range(1,51):
sq=a**2
l.append(sq)
t=tuple(l) #converting list to tuple
print(t)
(b)- A tuple (‘a’,’bb’,’ccc’,’dddd’,…..) that ends with 26 copies of the letter z.
l=list()
ch='a'
for a in range(1,27):
sq=ch*a
l.append(sq)
ch=chr(ord(ch)+1)
t=tuple(l) #converting list to tuple
print(t)
16. Write a python program to create a dictionary with the roll number, name and marks of n
students in a class and display the names of students who have scored marks above 75. 05/11/2022

n=int(input("Enter the number of students:"))


stu_data=["stu_name","stu_rollno","marks1"]
for i in range(0,n):
stu_name=input("Enter the name of the student:")
stu_rollno=int(input("Enter the roll number of the student:"))
marks1=int(input("Enter the marks f the student for 100:"))
dict={"name":'stu_name',"rollno":'stu_rollno',"marks":'marks1'}
if (int(marks1)>75):
print(dict['name'],"is having more than 75")
else:
print(dict['name'],"is not having more than 75")

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)

You might also like