[go: up one dir, main page]

0% found this document useful (0 votes)
229 views10 pages

Revision Tour 2 - 2marks

Uploaded by

j4siiiim
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)
229 views10 pages

Revision Tour 2 - 2marks

Uploaded by

j4siiiim
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/ 10

21.

Given the following dictionaries


Dict1={'Tuple': 'immutable', 'List': 'mutable', 'Dictionary':
'mutable', 'String': 'immutable'}
Which of the following will delete key:value pair for
key=„Dictionary‟ in the above mentioned dictionary?
(a) del Dict1['Dictinary']
(b) Dict1[„Dictionary‟].delete( )
(c) delete (Dict1.["Dictionary"])
(d) del(Dict1.[„Dictionary‟])
2 MARKS / 3 -MARKS
1. Write a statement in Python to declare a dictionary whose
keys are Sub1, Sub2, Sub3 and values are Physics,
Chemistry, Math respectively.
2. Debug the following code and underline the correction
made:
d=dict{ }
n=input("enter number of terms")
for i in range(n):
a=input("enter a character")
d[i]=a
3. Write the output of the code given below:
>>>squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
>>>print(squares.pop(4))
4. Write the output of the code given below :
Emp = { "SMITH":45000 , "CLARK":20000 }
Emp["HAPPY"] = 23000
Emp["SMITH"] = 14000
print( Emp.values())
5. What will be the output of the following Python code?
d1={"a":10,"b":2,"c":3}
str1=""
for i in d1:
str1=str1+str(d1[i])+" "
str2=str1[ : -1]
print(str2[: : -1])
6. Predict the output of the Python Code given below:
d={"Rohan":67,"Ahasham":78,"naman":89,"pranav":79}
print(d)
sum=0
for i in d:
sum+=d[i]
print(sum)
print("sum of values of dictionaries",sum)
7. Predict the output of
d={2:'b',4:'c'}
d1={1:'a'}
d.update(d1)
d[1]='v'
print(list(d.values()))
8. Mydict={ }
Mydict[(1,2,3)]=12
Mydict[(4,5,6)]=20
Mydict[(1,2)]=25
total=0
for i in Mydict:
total=total+Mydict[i]
print(total)
print(Mydict)
9. Write the output of the code given below:
d1 = {"name": "Aman", "age": 26}
d2 = {27:'age','age':28}
d1.update(d2)
print(d1.values())
10. Write the output of the following code given below:
Marks = {'Sidhi':65, 'Prakul':62, 'Suchitra':64, 'Prakash':50}
newMarks = {'Suchitra':66,'Arun':55,'Prkash':49}
Marks.update(newMarks)
for key,value in Marks.items():
print(key,'scored',value,'marks in Pre Board',end=' ')
if(value<55):
print(„and needs imporovement‟end=‟.‟)
print()
11. Write the output of the following Python program code:
my_dict = { }
my_dict[(1,2,4)] = 8
my_dict[(4,2,1)] = 10
my_dict[(1,2)] = 12
sum = 0
for k in my_dict:
sum += my_dict[k]
print (sum)
print(my_dict)
12. Predict the output of the following:
D={ }
T=("Raj","Anu","Nisha","Lisa")
for i in range(1,5):
D[i]=T[i-1]
print(D)
13. Predict the output of the following:
S="UVW"
L=[10,20,30]
D={ }
N=len(S)
for i in range(N):
D[L[i]]=S[i]
for K,V in D.items():
print(K,V,sep="*",end=",")
14. What will be the output, given by the following piece
of code:
D1= {"A":12, "B": 6, "C" : 50, "D" : 70}
print (50 in D1,"C" in D1,sep="#")
15. Predict the output of the following:
P=1400
D={'KTM':45,'RoyalEnfield':75,'Jawa':33,'TVS':89,
'Yamaha':111}
for j in D:
if(len(j)>5):
P=P-D[j]
print(j)
X={'Suzuki':1000,'Bajaja':21}
D.update(X)
print(X)
print(D)
print(D.get('Jawa','KTM'))

*****************************************************
2 MARKS / 3 MARKS
1. (a) >>>L=[1,"Computer",2,"Science",10,"PRE",30,"BOARD"]
>>>print(L[3:])
(b) Identify the output of the following Python statements.
>>>x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]
>>>y = x[1][2]
>>>print(y)
2. Write the output of following code:
lst1=[10,15,20,25,30]
lst1.insert(3,4)
lst1.insert(2,3)
print(lis[-5])
3. Write output for the following code:
list1=[x+2 for x in range(5)]
print(list1)
4. What will be the output of the following code?
a=[1,2,3,4]
s=0
for a[-1] in a:
print(a[-1])
s+=a[-1]
print(„sum=‟,s)
5. Predict the output of the following:
(i) L=[10,20]
L1=[30,40]
L2=[50,60]
L.append(L1)
L.extend(L2)
print(L)
5. Predict the output of the following:
(ii) M=[11, 22, 33, 44]
Q=M
M[2]+=22
L=len(M)
for i in range (L):
print("Now@", Q[L-i-1], "#", M[i])
6. Predict the output of the Python code given below:
l=[ ]
for i in range(4):
l.append(2*i+1)
print(l[::-1])
7. Predict the output of the following:
TXT = ["10","20","30","5"]
CNT = 3
TOTAL = 0
for C in [7,5,4,6]:
T = TXT[CNT]
TOTAL = float (T) + C
print (TOTAL)
CNT-=1
8. Write the output of the following:
x = [[1, 2, 3],[4, 5, 6],[7, 8, 9]]
result = []
for items in x:
for item in items:
if item % 2 == 0:
result.append(item)
print(result)
9. Write the output of the following python code:
Numbers =[9,18,27,36]
for num in Numbers:
for N in range(1,num%8):
print(N,"$",end="")
print()
10. Predict the output of the following:
List1 = list("Examination")
List2 =List1[1:-1]
new_list = []
for i in List2:
j=List2.index(i)
if j%2==0:
List1.remove(i)
print(List1)
11. Predict the output of the following:
fruit_list1 = ['Apple', 'Berry', 'Cherry', 'Papaya']
fruit_list2 = fruit_list1
fruit_list3 = fruit_list1[:]
fruit_list2[0] = 'Guava'
fruit_list3[1] = 'Kiwi'
sum = 0
for ls in (fruit_list1, fruit_list2, fruit_list3):
if ls[0] == 'Guava':
sum += 1
if ls[1] == 'Kiwi':
sum += 20
print(sum)
12. Predict the output of the following:
L1,L2=[10,15,20,25],[ ]
for i in range(len(L1)):
L2.insert(i,L1.pop())
print(L1,L2,sep='&')
14. Predict the output of the following:
L1=[10,20,30,20,10]
L2=[ ]
for i in L1:
if i not in L2:
L2.append(i)
print(L1,L2,sep='$')
15. Predict the output of the following:
num=[10,20,30,40,50,60]
for x in range(0,len(num),2):
num[x], num[x+1]=num[x+1], num[x]
print(num)
16. Predict the output of the following:
L=[1,2,3,4,5]
Lst=[]
for i in range(len(L)):
if i%2==1:
t=(L[i],L[i]**2)
Lst.append(t)
print(Lst)
17. Predict the output of the following:
sub=["CS", "PHY", "CHEM", "MATHS","ENG"]
del sub[2]
sub.remove("ENG")
sub.pop(1)
print(sub)
18. Predict the output of the following:
Predict the output:
list1 =['Red', 'Green', 'Blue', 'Cyan','Magenta','Yellow',]
print(list1[-4:0:-1])
19. Predict the output of the following:
L=[10,20,40,50,60,67]
L[0:3]="100"
print(L)
20. Predict the output of the following:
lst = [40, 15, 20, 25, 30]
lst.sort()
lst.insert(3, 4)
lst.append(23)
print(lst)
21. Predict the output of the following:
L=[10,2,5,-1,90,23,45]
L.sort(reverse=True)
S=L.pop(2)
L.insert(4,89)
L.sort()
L.remove(90)
print(L)
22. Predict the output of the following:
L=[10,2,5,-1,90,23,45]
L.sort(reverse=True)
G=L.append(L.pop(L.pop()))
print(G)
23. Predict the output of the following:
L=['30','40','20','50']
count=3
Sum=0
P=[]
for i in[6,4,5,8]:
T=L[count]
Sum=float(T)+i
P.append(Sum)
count-=1
print(P)
print(P[3:0:-1])
for i in[0,1,2,3]:
P[i]=int(P[i])+10
print(P)
24. Predict the output of the following:
L=['FORTRAN','C++','Java','Python']
L.insert(2,"HTML")
del L[4]
L.remove('Java')
L.pop()
L.insert(1,"PHP")
L.sort()
L.pop()
print(L)
*********************************************************
2 –MARKS / 3 - MARKS
1. If S="python language" is a Python string, which method
will display the following output 'P' in uppercase and
remaining in lower case?
2. Rewrite the following code :
for Name in [Aakash, Sathya, Tarushi]
IF Name[0]= 'S':
print(Name)
3. Consider the given Python string declaration:
>>> mystring = 'Programming is Fun'
>>> printmystring[-50:10:2].swapcase())
4. Rewrite the following:
STRING=""WELCOME
NOTE = " "
for S in range(0,8):
if STRING[S]= ‟E‟:
print(STRING(S))
Else:
print "NO"
5. Given is a Python string declaration:
>>>Wish = "## Wishing All Happy Diwali @#$"
Write the output of >>>Wish[ -6 : : -6 ]
6. Predict the output of the following:
Name = "cBsE@2051"
R=" "
for x in range (len(Name)):
if Name[x].isupper ( ):
R = R + Name[x].lower()
elif Name[x].islower():
R = R + Name[x].upper()
elif Name[x].isdigit():
R = R + Name[x-1]
else:
R = R + "#"
print(R)
7. Predict the output of the following:
>>> 'he likes tea very much'.rstrip('crunch')
>>> 'There is a mango and an apple on the table'.rstrip('ea')
7. Find the output
Msg1="WeLcOME"
Msg2="GUeSTs"
Msg3=""
for I in range(0,len(Msg2)+1):
if Msg1[I]>="A" and Msg1[I]<="M":
Msg3=Msg3+Msg1[I]
elif Msg1[I]>="N" and Msg1[I]<="Z":
Msg3=Msg3+Msg2[I]
else:
Msg3=Msg3+"*"
print(Msg3)
8. Predict the output of the following:
s="3 & Four"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'A' and s[i] <= 'Z'):
m = m +s[i].upper()
elif (s[i] >= 'a' and s[i] <= 'z'):
m = m +s[i-1]
if (s[i].isdigit()):
m = m + s[i].lower()
else:
m = m +'-'
print(m)
9. Name="PythoN3.1"
R=" "
for x in range(len(Name)):
if Name[x].isupper():
R=R+Name[x].lower()
elif Name[x].islower():
R=R+Name[x].upper()
elif Name[x].isdigit():
R=R+Name[x-1]
else:
R=R+"#"
print(R)
10. Find output generated by the following code:
string="aabbcc"
count=3
while True:
if string[0]=='a':
string=string[2:]
elif string[-1]=='b':
string=string[:2]
else:
count+=1
break
print(string)
print(count)
11. Write the output of the code snippet.
txt = "Time, will it come back?"
x = txt.find(",")
y = txt.find("?")
print(txt[x+2:y])
12. Predict the output of the following:
S='Python Programming'
L=S.split()
S=','.join(L)
print(S)
13. Predict the output of the following:
S="Good Morning Madam"
L=S.split()
for W in L:
if W.lower()==W[::-1].lower()
print(W)
*********************************************************

You might also like