Revision Tour 2 - 2marks
Revision Tour 2 - 2marks
*****************************************************
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)
*********************************************************