UTKARSHSINGHCLASS12CSRECORDFILE Final2023
UTKARSHSINGHCLASS12CSRECORDFILE Final2023
Board Rollno:
DELHI PUBLIC SCHOOL
NERUL , NAVI MUMBAI
Certificate
Number____________________.
examination.
INDEX
SNO Program Pagen Date Sign
o
1.
Working with nested tuples
CODE:
st=()
sum=0
avg=0
for i in range(5):
print("\nPlease enter the marks for student ",i+1)
m1=int(input('Please enter the marks '))
m2=int(input('Please enter the marks '))
m3=int(input('Please enter the marks '))
st+=(m1,m2,m3)
sum=m1+m2+m3
avg=sum/3
print('Total marks of student',i+1,' is ',sum)
print('average marks of student',i+1,' is ',avg)
OUTPUT:
=
PROGRAM 2:
Q2. Accept a string and check if it contains all unique
characters. Display the entered string and the message
UNIQUE or NOT UNIQUE Ex: If entered string is ‘apple’
display NOT UNIQUE and if the entered string is
‘bats*29’ display UNIQUE.
CODE:
OUTPUT:
Please enter a string ABCD_123
UNIQUE
Please enter a string APPLE
NOT UNIQUE
Program 3:
Q3. Accept a string S and a word W from the user and do
the following(Use in built string methods ) a. Check if
the string begins with the accepted word and display
appropriate messages. b. Check if the string ends with
the accepted word and display appropriate messages. c.
Partition the string with the accepted word and display
the partitioned tuple. d. Replace all occurrences of the
given word by ‘***’ in the string and display the
replaced string. e. Swap the case of the string and
display the swapped string. f. Join every word of the
given string with ‘#’ and display the joined string
#partition
print('\nPartitioned String: ')
print(S.partition(W))
#replace
print('\nreplaced String: ')
print(S.replace(W,'***'))
#swap
print('\nCase swapped String: ')
print(S.swapcase())
#join
print('\n# joint String: ')
print('#'.join(S.split()))
OUTPUT:
Partitioned String:
('', 'MY', ' NAME IS UTKARSH')
replaced String:
*** NAME IS UTKARSH
Case swapped String:
my name is utkarsh
# joint String:
MY#NAME#IS#UTKARSH
PROGRAM 4:
CODE:
L = eval(input('Please enter a list of eight numbers '))
L1=L.copy()
for i in range(0,8,2):
L[i],L[i+1]=L[i+1],L[i]
print('The changed list after swapping is',L)
print("the original list is :",L1)
OUTPUT:
CODE:
d={}
for i in range(26):
d[chr(97+i)]=chr(122-i)
print('mirror alphabet dictionary \n', d)
S = input('Please enter a lowercase string ')
mirror=''
for i in S:
mirror+=d[i]
print(mirror)
OUTPUT:
Accept a product code and name from the user and add
into the dictionary. Update: Accept a product code and
displayed.
CODE:
PRODUCT={}
end = ''
pcode=0
pname=''
while end!='no':
S = input('Please enter the number beside the options to perform the functions
\n1.Add \n2.Update \n3.Delete \n4.Display\n ').lower()
if S=='1':
pcode = input('Please enter the product code ')
pname = input('Please enter the product name ')
PRODUCT[pcode]=pname
end=input('Do you want to continue? ').lower()
elif S=='2':
pcode = input('Please enter the product code ')
pname = input('Please enter the product name ')
PRODUCT[pcode]=pname
end=input('Do you want to continue? ').lower()
elif S=='3':
pcode = input('Please enter the product code ')
if pcode in PRODUCT:
del PRODUCT[pcode]
else:
print('The product does not exist')
end=input('Do you want to continue? ').lower()
elif S=='4':
pcode = input('Please enter the product code ')
if pcode in PRODUCT:
print('pname of the product is', PRODUCT[pcode])
else:
print('The product does not exist')
end=input('Do you want to continue? ').lower()
OUTPUT:
Please enter the number beside the options to perform the functions
1.Add
2.Update
3.Delete
4.Display
1
Please enter the product code SMG001
Please enter the product name SAMSUNGGALAXYULTRA
Do you want to continue? YES
Please enter the number beside the options to perform the functions
1.Add
2.Update
3.Delete
4.Display
2
Please enter the product code SMG002
Please enter the product name WIRELESSHEADPHONES
Do you want to continue? YES
Please enter the number beside the options to perform the functions
1.Add
2.Update
3.Delete
4.Display
3
Please enter the product code SMG001
Do you want to continue? YES
Please enter the number beside the options to perform the functions
1.Add
2.Update
3.Delete
4.Display
4
Please enter the product code SMG002
pname of the product is WIRELESSHEADPHONES
Do you want to continue? NO
PROGRAM 7:
the list C.
Code:
for i in C:
for j in S:
if i in j:
S.remove(j)
print(S)
OUTPUT:
['good', 'for']
PROGRAM 8:
Accept a list of tuples T. Each tuple has numbers in it.
Accept another integer K . Display all those tuples which
have numbers having K digits in it.
CODE:
for i in T:
for j in i:
if len(str(j))!=K:
break
else:
print(i)
OUTPUT: