0% found this document useful (0 votes)
11 views23 pages

ANKIT CHAUHAN PRACTICAL FILE -6

Uploaded by

kumarrashish1206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views23 pages

ANKIT CHAUHAN PRACTICAL FILE -6

Uploaded by

kumarrashish1206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Sarvodaya Vidyalaya

Sec-7,Rohini(1413074)

Computer Science
Practical File
Class-XI
(2024-25)
​ ​

SUBMITTED TO :​​ ​ ​ ​ Submitted By :


Mr. Sunil kumar​ Ankit chauhan​
Lec. Comp. Sci.​​ ​ ​ ​ ​ XI-A
CERTIFICATE
This is to certify that…. Ankit chauhan….. roll no…..49
of class- XI-A has satisfactorily completed laboratory
work in Computer science with Python(083) for the Practical
Examination 2024-2025 as prescribed by CBSE board.

Signature of External Examiner Signature of Internal Examiner

​ ​ ​
INDEX
S Practical Title Teacher's
No Signature

1 Generate the following pattern.

2 Generate the pattern using nested loop

3 Write a python program to check if the minimum element of a tuple lies at the
middle position of the tuple.

4 Find the largest/smallest number in a list/tuple.

5 Write a python program to count and display the number of vowels,


consonants, uppercase, lowercase characters in string.

6 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.

7 Input a list/tuple of elements, search for a given element in the list/tuple.

8 write a program to find the largest/smallest number.

9 Write a program to find the frequency of all elements of a list. Also print the list
of unique elements in the list and duplicate elements in the given list.

10 Write a program to create a dictionary with the roll number,name and marks of
a student in a class and display the name of students who have marks above
75 .

11 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.
12 Write a program to input the value of x and n and print the sum of the
following series:

13 Input a number and check if the number is a prime or composite number.

14 Write a python program to display the terms of a Fibonacci series till 100.

15 Write a python program to compute the greatest common divisor and least
common multiple of two Integers.

16 Write a python program to implement a simple calculator for two input


numbers. Offer choices through a Menu.

17 Write a python program that removes all capitalization and common


punctuation from a string.

18 Input a list of numbers and swap elements at the even location with the
elements at the odd location.

19 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.

20 Program to obtain three numbers and print their sum.


PROGRAM 1
GENERATE THE THE FOLLOWING PATTERN
for i in range(5,0,-1):
for j in range(1,1+i):
print(j,end=" ")
print(" ")
PROGRAM 2

GENERATE THE PATTERN USING NESTED LOOP

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 python program to check if the minimum element of a tuple lies at the
middle position of the tuple.
tup=eval(input("enter a tuple"))
ln = len(tup)
lies =False
mn = min(tup)
if ln % 2 == 0:
half=ln/2
if mn == tup[half] or mn == tup[half-1]:
lies=True
else:
half = ln//2
if mn == tup[half]:
lies=True
if lies==True:
print("minimum lies at tuple's middle")
else:
print("minimum does not lies at tuple's middle")
PROGRAM 4
Find the largest/smallest number in a list/tuple

l1=eval(input("enter the tuple/list:"))


mn=min(l1)
mx=max(l1)
print("The largest number in the tuple/list is:",mn)
print("The smallest number in the tuple/list is",mx)
PROGRAM 5
Write a python program to count and display the number of vowels,
consonants, uppercase, lowercase characters in string.
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
summ = 0
temp=n
while temp > 0:
digit = temp % 10
summ += digit ** 3
temp//= 10
if n == summ:
print("This is an Armstrong number")

PROGRAM 6
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.
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()
print("change case of string", case)
PROGRAM 7
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 8
write a program to find the largest/smallest number.

list=eval(input("Enter a list"))
print("the list is:",list)
mx=max(list)
mn=min(list)
print("maximum number in the list:",mx)
print("minimum number in the list:",mn)
PROGRAM 9
Write a program to find the frequency of all elements of a list. Also
print the list of unique elements in the list and duplicate elements in
the given list.

list=eval(input("Enter list:"))
length=len(list)
unique=[]
dup1=[]
count=i=0
while i<length:
element=list[i]
count=1 #count as 1 for the elements at list[i]
if element not in unique and element not in dup1:
i+=1
for j in range(i,length):
if element==list[j]:
count+=1
else:
print("element",element,"frequency",count)
if count==1:
unique.append(element) #when element is found in unique or dup1
list
else:
dup1.append(element)
else:
i+=1
print("Original list",list)
print("unique element",unique)
print("Duplicates elements list",dup1)

PROGRAM 10
Write a program to create a dictionary with the roll number,name and
marks of a student in a class and display the name of students who
have marks above 75 .

n=int(input("how many students?:"))


stu={}
for i in range(1,n+1):
print("Enter detail of student",(i))
rollno=int(input("Roll no.:"))
name=input("name:")
marks=float(input("marks:"))
d={"roll_no":rollno,"name":name,\
"marks":marks }
key="stu"+str(i)
stu[key]=d
print("Student with marks.75are:")
for i in range(1,n+1):
key="stu"+str(i)
if stu[key]["marks"]>=75:
print(stu[key])
PROGRAM 11
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.

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 12
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

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)

PROGRAM 13
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 14
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 15
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 16
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 17
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())

PROGRAM 18
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 19
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.

d1={'s':205,'a':108,'k':117}
d2={'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(d1)
print(d2)
print("The resultant dictionary :")
print(dict3)
PROGRAM 20
Program to obtain three numbers and print their sum.

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


num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
total_sum = num1 + num2 + num3
print("The sum of the three numbers is:", total_sum)

You might also like