Rajkiya Pratibha Vikas
Vidyalaya
Sec-11,Rohini(1413076)
Computer Science
Practical File
Class-XI
(2022-23)
Submitted To: Submitted By:
Ms. Vineeta Name:sakshi
Lect. Comp. Sci. Class: XI- B
Roll no : 14
INDEX
S. Practical Title Teacher’s
No Signature
1 Write a python program to input three numbers and display the largest / smallest
number.
2 Generate the following patterns using nested loop.
(a) 1 2 3 4 5 (b) *
1234 * *
123 * *
12 * *
1 *
3 Write a program to input the value of x and n and print the sum of the following
series:
(a)1+x+x^2+x^3+x^4+ ..................x^n
(b)1-x+x^2-x^3+x^4 -.....................x^n
4 Write a python program to determine whether a number is a perfect number, an
armstrong number or a palindrome.
5 Input a number and check if the number is a prime or composite number.
6 Write a python program to display the terms of a Fibonacci series till 100.
7 Write a python program to compute the greatest common divisor and least
common multiple of two integers.
8 Write a python program to implement a simple calculator for two input numbers.
Offer choices through a menu.
9 Write a python program to input a string and determine whether it is a palindrome
or not; convert the case of characters in a string.
10 Write a python program to count and display the number of vowels, consonants,
uppercase, lowercase characters in string.
11 Find the largest/smallest number in a list/tuple
12 Input a list of numbers and swap elements at the even location with the elements at
the odd location.
13 Input a list/tuple of elements, search for a given element in the list/tuple.
14 Write a python program to find frequencies of all elements of a list. Also, print the
list of unique elements in the list and duplicate elements in the given list.
15 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.
16 Write a python program to create a third dictionary from two dictionaries having
some common keys, in such a way so that the values of common keys are added in
the third dictionary.
17 Write a python program to check if the minimum element of a tuple lies at the
middle position of the tuple.
18 Write a python program to check if the elements in the first half of a tuple are
sorted in ascending order or not.
19 Write a python program that displays options for inserting or deleting elements in
a list. If the user chooses a deletion option, display a submenu and ask if an
element is to be deleted with value or by using its position or a list slice is to be
deleted.
20 Write a python program that removes all capitalization and common punctuation
from a string s.
PROGRAM1:
Write a python program to input three numbers and display the
largest / smallest number.
num1= int(input("enter the number1:"))
num2= int(input("enter the number2:"))
num3= int(input("enter the number3:"))
if num1>num2 and num1>num3:
print("greater number is", num1)
else:
( num2>num3)
print("smallest number is=", num3)
if num2>num1 and num2>num3:
print("greater number is", num2)
else:
( num1>num3)
print("smallest number is=", num3)
if num3>num1 and num3>num2:
print("greater number is", num3)
else:
( num1>num3)
print("smallest number is=", num3)
PROGRAM 2:
GENERATE THE THE FOLLOWING PATTERN
(a)
for i in range(5,0,-1):
for j in range(1,1+i):
print(j,end=" ")
print(" ")
(B)
for i in range(1,8):
for j in range(1,8):
if((i+j==5)or(j-i==3)or(i+j==11)or(i-j==3)):
print("*",end='')
else:
print(" ",end='')
print(" ")
PROGRAM 3:
Write a program to input the value of x and n and print the sum of the
following series:
(a)1+x+x^2+x^3+x^4+ ..................x^n
(b)1-x+x^2-x^3+x^4 -.....................x^n
(a)
x= int(input("enter the value of x:"))
n= int(input("enter the value of n:"))
sum=0
for i in range(n+1):
k=x**i
sum= sum+k
print("with X",x,"with n",n,"SUM", sum)
(B)x= int(input("enter the value of x:"))
n= int(input("enter the value of n:"))
sum=0
for i in range(n+1):
j=(-1)**i
k=x**i
sum= sum+k
print("with X",x,"with n",n,"SUM", sum)
PROGRAM 4
Write a python program to determine whether a number is a
perfect number, an armstrong number or a
Palindrome.
print("to find whether a number is perfect no,palindrome or an armstrong no:")
n=int(input("enter number:"))
#for perfect no
sum1 = 0
for i in range(1, n):
if(n % i == 0):
sum1 = sum1 + i
if (sum1 == n):
print(n,"The number is a Perfect number!")
else:
print(n,"The number is not a Perfect number!")
#for palindrome no
temp=n
rev=0
while temp>0:
dig=temp%10
rev=rev*10+dig
temp=temp//10
if(n==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
#for armstrong no
sum = 0
temp=n
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp//= 10
if n == sum:
print("This is an Armstrong number")
PROGRAM 5
Input a number and check if the number is a prime or composite number.
num = int(input("Enter any number : "))
if num > 1:
for i in range(2, num):
if (num % i) == 0:
print(num, "it is a COMPOSITE number")
break
else:
print(num, "is a PRIME number")
elif num == 0 or 1:
print(num, "is a neither Prime NOR Composite number")
else:
print()
PROGRAM 6
Write a python program to display the terms of a Fibonacci series
till 100.
t= int(input("how many terms?(enter2+value):"))
first=0
second=1
print("/nFibonacci series is:")
print(first,",",second,end=",")
for i in range(2,t):
next=first+second
print(next,end=",")
first= second
second= next
PROGRAM 7
Write a python program to compute the greatest common
divisor and least common multiple of two
integers.
x=int(input("enter first number:"))
y=int(input("enter second no:"))
if x>y:
smaller=y
else:
smaller=x
for i in range(1,smaller+1):
if((x%i==0)and(y%i==0)):
hcf=i
lcm=(x*y)/hcf
print("The H.C.F. of",x,"and",y,"is",hcf)
print("The L.C.M. of",x,"and",y,"is",lcm)
PROGRAM 8
Write a python program to implement a simple calculator for
two input numbers. Offer choices through a
Menu
print("calculator")
print("enter two numbers below")
n1=float(input("enter first no:"))
n2=float(input("enter second no:"))
cm=0
while cm<5:
print("calculator menu:")
print("1.add")
print("2.subtract")
print("3.multiply")
print("4.divide")
print("5.exit")
cm=int(input("Enter choices(1-5):"))
if cm==1:
print("sum:",n1+n2)
elif cm==2:
print("difference:",n1-n2)
elif cm==3:
print("product:",n1*n2)
elif cm==4:
print("quotient",n1/n2)
elif cm==5:
break
else:
print("invalid choice")
PROGRAM 9
Write a python program to input a string and determine whether it is a
palindrome or not; convert the case of characters in a string.
print("change case of string", case)
string=input("Enter string:")
if(string==string[::-1]):
print("The string is a palindrome")
else:
print("The string isn't a palindrome")
case= string.swapcase()
PROGRAM 10
Write a python program to count and display the number of vowels,
consonants, uppercase, lowercase
characters in string.
string = input("Enter Your String : ")
vowels = consonants = uppercase = lowercase = 0
vowels_list = ['a','e','i','o','u','A','E','I','O','U']
for i in string:
if i in vowels_list:
vowels += 1
if i not in vowels_list:
consonants += 1
if i.isupper():
uppercase += 1
if i.islower():
lowercase += 1
print("Number of Vowels in this String = ", vowels)
print("Number of Consonants in this String = ", consonants)
print("Number of Uppercase characters in this String = ", uppercase)
print("Number of Lowercase characters in this String = ", lowercase)
uppercase= string.lower()
lowercase= string.upper()
print("display of uppercase form of string", uppercase )
print("display of lowercase form of string", lowercase)
PROGRAM 11
Find the largest/smallest number in a list/tuple
tup=eval(input("enter your tuple= "))
minimum = min(tup)
maximum=max(tup)
print("minimum element of your tuple/ list",minimum)
print("maximum element of your tuple/list is:",maximum)
PROGRAM 12
Input a list of numbers and swap elements at the even location with
the elements at the odd location.
val=eval(input("Enter a list:"))
print("original list:",val)
ln=len(val)
if ln%2 !=0:
ln=ln-1
for i in range(0,ln,2):
print(i,i+2)
val[i],val[i+1]=val[i+1],val[i]
print("list after swapping:",val)
PROGRAM 13
Input a list/tuple of elements, search for a given element in the
list/tuple.
a= eval(input("enter the input="))
length =len(a)
element= int(input(" enter the element to be searched for ="))
for i in range(0, length):
if element== a[i]:
print("element is found at index", i)
break
else:
(" element is not found at index", i )
PROGRAM 14
Write a python program to find frequencies of all elements of a list.
Also, print the list of unique elements
in the list and duplicate elements in the given list.
print("my name is sakshi")
list=eval(input("enter the list:"))
length= len(list)
uniq=[]
dupl=[]
count=i=0
while i< length:
element= list[i]
count=0
if element not in uniq and element not in dupl:
i +=1
for j in range(i, length):
if element == list[j]:
count+= 1
if count==1:
uniq.append(element)
else:
dupl.append(element)
print("element", element, "frequency:", count)
else:
i+=1
print("original list:", list)
print("unique elements list",uniq)
print("duplicate elements list", dupl )
PROGRAM 15
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.
n=int(input("How many Students?"))
a={}
for i in range(1,n+1):
print("Enter details of Student",(i))
rollno=int(input("Roll number:"))
name=input("Name:")
marks=float(input("Marks:"))
d={"Roll_no":roll no,"Name":name,\
"Marks":marks}
key="a"+str(i)
a[key]=d
print("Students with marks>75 are:")
for i in range (1,n+1):
key="a"+str(i)
if a[key]["Marks"]>=75:
print(a[key])
PROGRAM 16
Write a python program to create a third dictionary from two
dictionaries having some common keys, in
such a way so that the values of common keys are added in the third
dictionary.
dict1={'s':205,'a':108,'k':117}
dict2={'a':234,'h':20,'k':450}
dict3=dict(d1)
dict3.update(d2)
for i,j in d1.items():
for x,y in d2.items():
if i==x:
dict3[i]=(j+y)
print("Two given dictionaries are: ")
print(dict1)
print(dict2)
print("The resultant dictionary :")
print(dict3)
PROGRAM 17
WRITE A PROGRAM TO CHECK IF THE MINIMUM ELEMENTS OF A
TUPLE LIES AT THE MIDDLE OF TUPLE.
PROGRAM
tup=eval(input("enter your tuple= "))
length=len(tup)
lies=False
min=min(tup)
if length % 2==0:
half=length/2
if min==tup[half] or min==tup[half-1]:
lies=true
else:
half=length/2
if min==tup[half]:
lies=true
if lies==true :
print("minimum element lies on middle partition of tuple ")
else:
print("minimum element does not lie on middle partition of element)
PROGRAM 18
Write a program to check if the elements in the first half of the tuple
are sorted in ascending order or not .
Program:-
tup=eval(input("enter your tuple="))
length=len(tup)
mid = length//2
if length% 2==1:
mid=mid+1
half=tup[:mid]
if sorted(half)==list(tup[:mid]):
print("first half of element is sorted ")
else:
print("first half of element is not sorted ")
PROGRAM 19
Write a python program that displays options for inserting or deleting elements in
a list. If the user chooses a deletion option, displays a submenu and asks if an
element is to be deleted with value or by using position
or a list slice is to be deleted.
val=[ 17, 23, 18, 19]
print("The list is : ", val)
print("Deletion Menu")
print("1. Delete using Value")
print("2. Delete using index")
print("3. Delete a sublist")
dch=int(input ("Enter choice :"))
if dch==1:
item=int (input ("Enter item to be deleted :"))
val.remove(item)
print("List now is : ", val)
elif dch==2:
index=int(input("Index of item to be deleted :"))
val.pop(index)
print("List now is : ", val)
elif dch==3:
l=int(input("Lower limit of list slice :"))
h=int(input ("Upper limit of list slice :"))
del val[1:h]
print("List now is :", val)
else:
print("valid choices are 1/2/3 only.")
PROGRAM 20
Write a python program that removes all capitalization and common
punctuation from a string.
punctuation= "!@#$%^&*_-+={}[]\|:;'?/>,<"
s= input("enter the string:")
no_punct =""
for i in s:
if i not in punctuation:
no_punct = no_punct+i
print(no_punct.lower())