Practical File Solutions
Practical File Solutions
2 CPE ITARSI
CLASS-XI
COMPUTER SCIENCE (083)
PRACTICAL FILE [2024-25)
Program#3: Write a program to input two numbers and display the larger/
smaller number.
# Program to display the larger of two numbers
Num1 = int(input("Enter the first number :"))
Num2= int(input("Enter the second number :"))
if Num1>Num2:
print(Num1, “is larger”)
else:
print(Num2, “is larger”)
1
# Program to calculate percentage and assign grade
print("Enter the marks of the student in 5 subjects out of 100")
sub1= int(input("Enter marks in subject1 :"))
sub2= int(input("Enter marks in subject2 :"))
sub3= int(input("Enter marks in subject3 :"))
sub4= int(input("Enter marks in subject4 :"))
sub5= int(input("Enter marks in subject5 :"))
per = (sub1+sub2+sub3+sub4+sub5)/5
if per>=75:
grade = 'A'
elif per>=65 and per<75:
grade = 'B'
elif per>=50 and per<65:
grade = 'C'
else:
grade = 'D'
print("Percentage scored = ",per,"%", "Grade = ", grade)
#Pattern-1
n = int(input(“Enter the no. of rows”))
for i in range(1, n+1):
for j in range(i):
print("*", end=" ")
print("\n")
print()
#Pattern-2
n = int(input(“Enter the no. of rows: ”))
for i in range(1, n+1):
for j in range(1, n+1):
print(j, end=" ")
print("\n")
n-=1
print()
#Pattern-3
n = int(input(“Enter the no. of rows: ”))
for i in range(1,n+1):
for j in range(65,65+i):
print(chr(j),end=' ')
print()
2
Program#7: Write a program to input the value of x and n and print the
sum of the following series:
1. 1+x + x² + x³ + … + xⁿ
2. 1-x + x² – x³ + … + xⁿ
𝐱² 𝐱³
3. x+ 𝟐 + 𝟑 + … + xⁿ
#Program to find the sum of series-1: 1+x + x² + x³ + … + xⁿ
x = float(input("Enter the value of x : "))
n = float(input("Enter the value of n : "))
sum = 0
for i in range(n+1):
sum = sum+ x**i
print("Sum of Series is :",sum)
𝐱² 𝐱³
#Program to find the sum of series-3: x+ 𝟐 + 𝟑 + … + xⁿ
x = float(input("Enter the value of x : "))
n = float(input("Enter the value of n : "))
sum = 0
for i in range(1, n+1):
sum = sum+ (x**i)/i
print("Sum of Series is :",sum)
3
Program#10: Write a program to determine whether a number is a perfect
number or not.
[Note: a perfect number is a number that is half the sum of all of its
positive divisors (including itself)
Example: The first perfect number is 6, because 1,2 and 3 are its proper
positive divisors and (1+2+3+6)/6 = 6
Other Perfect numbers are: 28, 496, and 8128 etc]
# Program to check perfect number
num = int(input("Enter a positive integer>0: "))
s=0
for i in range(1,num):
if num%i==0:
s = s + i
if s == n:
print( n,"is perfect number")
else:
print( n, "is not perfect number")
4
Program#13: Write a program to input a number and check if the number is
prime or composite number.
#Program to check prime number
num= int(input("Enter a positive Integer>0: "))
if num == 1:
print(num," is neither prime nor composite")
elif num>1 :
for i in range(2,num//2+1):
if(num%i == 0):
print(num,"is not prime ")
break
else:
print(num," is prime")
else :
print("Please enter positive number only ")
5
Program#16: Write a program to compute the greatest common divisor and
least common multiple of two integers.
#Program to compute the GCD and LCM of two integers
x=int(input("Enter first number :"))
y=int(input("Enter Second number: "))
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if x % i == 0 and y % i == 0:
gcd = i
print('GCD of', x ,'and' ,y ,'is',gcd)
lcm=x*y/gcd
print('LCM of', x ,'and' ,y ,'is',lcm)
or
L=eval(input("Enter a list: "))
print("Min : ",min(L),"Max : ",max(L))
or
L=eval(input("Enter a list: "))
Max=Min=L[0]
for i in range(1,len(L)):
if L[i]>Max:
Max=L[i]
if L[i]<Min:
Min=L[i]
print("Min : ",Min,"Max : ",Max)
7
Program#21: Write a program to display the second largest item in a
given list of integers.
#Program to find the second largest item from a given list
L =eval(input("Enter the list: "))
print("Original List:",L)
max1=max(L)
print(“Largest number is: ”,max1)
max2=L[0]
for i in range(1, len(L)):
if L[i]>max2 and L[i]<max1:
max2=L[i]
print("Second largest number is:",max2)
Program#22: Write a program to remove all even numbers from a given list
of integers.
#Program to remove all even numbers from a given list
L =eval(input("Enter the list: "))
print("Original List:",L)
for i in L:
if i%2==0:
L.remove(i)
print("Modified list: ",L)
8
Program#25: Write a program to create a dictionary with roll number,
name and marks of n students in a class and display the names of
students who have scored marks above 75
# Program to create a dictionary for marks of n students
n = int(input("Enter number of students :"))
result = {}
for i in range(n):
print("Enter Details of students :",i+1)
rno = int(input("Enter Roll number :"))
name = input("Name :")
eng = float(input("Enter English Marks: "))
math = float(input("Enter Math Marks: "))
comp = float(input("Enter Computer Marks: "))
phy = float(input("Enter Physics Marks: "))
chem = float(input("Enter Chemistry Marks: "))
total = eng + math + comp + phy + chem
percentage = (total / 500) * 100
result[rno] = [name,percentage]
print(result)
for s in result:
if result[s][1]>75:
print("Following students having more than 75 marks:")
print(result[s][0])
else:
print(“None of the students scored marks>75”)