Output : question
1. Find the output of the following code :
str="Python123.com"
for i in range(len(str)):
if(str[i].isalpha()):
print(str[i-1])
if(str[i].isdigit()):
print(str[i])
Ans : mPytho123.co
2. Find the output of the following code :
list1 = ["python", "list", 1952, 2323, 432]
list2 = ["this", "is", "another", "list"]
print(list1[1:4])
print(list1[1:])
print(list1[0])
print(list1 * 2)
print(list1 + list2)
Ans : ['list', 1952, 2323]
['list', 1952, 2323, 432]
python
['python', 'list', 1952, 2323, 432, 'python', 'list', 1952, 2323, 432]
['python', 'list', 1952, 2323, 432, 'this', 'is', 'another', 'list']
3. Find the output of the following program
str1 ='P@ssW0rd',
str2 =""
for ch in str1:
if ch>='A' and ch<='Z':
ch=chr(ord(ch)+33)
elif ch>='a' and ch<='z':
ch=chr(ord(ch)-31)
else:
ch='*'
str2=ch+str2
print(str2)
Ans:
4. a) If a = [5,4,3,2,1,0,5] evaluate the following expression
i. a[-1]
ii. a[a[a[a[3]+1]]]
b) What is the length of the tuple shown below : t = (((( ‘a’,1),’b’,’c’),’d’,2),’e’,3,5)
Ans : a) i) 5) ii) 2
b) 4
5. Find the output of the following
l = [6 , 3 , 8 , 10 , 4 , 6 , 7]
print( '@', l[3] - l[2])
for i in range (len(l)-1,-1,-2):
print( '@',l[i],end='' )
Ans : @ 2
@7@ 4@ 8@ 6
6. Find the output of the following
def Diff(N1,N2):
if N1>N2:
return N1-N2
else:
return N2-N1
NUM= [10,23,14,54,32]
for CNT in range (4,0,-1):
A=NUM[CNT]
B=NUM[CNT-1]
print(Diff(A,B),'#', end=' ')
7. Find the output of the following
s="welcome2cs"
n = len(s)
m=""
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m =m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)
Ans : sELCcME&Cc
8. Find the output of the following
v=25
def fun(ch):
v=50
print(v,end=ch)
v*=2
print(v, end=ch)
print(v, end="*")
fun("!")
print(v)
Ans: 25*50!100!25
9. Find the output of the following
def ChangeVal(M,N):
for i in range(N):
if M[i] %5 == 0:
M[i] //=5
if M[i] %3 == 0:
M[i] //=3
L = [25,8,75,12]
ChangeVal(L,4)
for i in L:
print(i,end="#")
Ans : 5#8#5#4#
10. Find the output of the following
a=30
def call (x):
global a
if x%2==0:
x=x+a
else:
x=x-a
return(x)
print(call(67), end="#")
print(call(40),end="#")
Ans : 37#70#
11. Find the output of the following
val = 100
def display(N):
global val
val = 50
if N%14==0:
val = val + N
else:
val = val - N
print(val, end="@")
display(40)
print(val)
Ans : 100@10
12. Find the output of the following
def div(L,n):
for i in range(0,n):
if L[i]%5==0:
L[i]+=5
else:
L[i]=L[i]//2
t=[45,20,23,54,5]
div(t,len(t))
for i in t:
print(i,end="#")
Ans : 50#25#11#27#10#
13. Find the output of the following
def calc(u):
if u%2==0:
return u+10
else :
return u+2
def pattern(M,B=2):
for I in range (0,B):
print(calc(I),M,end=’ ’)
pattern('#',4)
pattern('@',3)
Ans : 10 #3 #12 #5 #10 @3 @12 @
14. Find 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)
Ans : [] [25, 20, 15, 10]
15. Find the output of the following
R=0
def change(A,B):
global R
A+=B
R+=3
print(A,B,sep =”#”, end="")
change(10,2)
print(R,end='%')
change(B=3,A=2)
Ans: 12# 2
3 % 5# 3
16. Find the output of the following
str = "CBSE Digital India"
for i in range(len(str)-1,0,-1):
if str[i].isupper():
print(str[i].lower(),end="")
if i%2==0:
if str[i].lower():
print(str[i].upper(),end="")
else:
print('$',end="")
Ans : $I$Ni$ $A$I$Id$ e$sSb$
17. Given is a Python string declaration:
myexam="@@CBSE Examination 2022@@"
Write the output of: print(myexam[::-2])
ANS : otnmx SC@
18. Find the output of the following
def CALLME(n1=1,n2=2):
n1=n1*n2
n2+=2
print(n1,n2)
CALLME()
CALLME(3)
Ans : 2 4
64
19. Find the output of the following
a) Given is a Python List declaration:
list= [10, 20, 30, 40, 50, 60, 70, 80]
print(list[ : : 2])
b) squares = {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
print(squares.pop(4))
Ans : a) [10, 30, 50, 70] b) 16
20. Find the output of the following
a) List1=[10,[20,30,40],50,60,70,80,90]
print(List1[1:3:2])
b) lst1=[10,15,20,25,30]
lst1.insert(3,4)
lst1.insert(2,3)
print(lst1[-5])
c) mystring = ‘Programming is Fun’
print(mystring[-50:10:2].swapcase())
d) message='FirstPreBoardExam@2022-23'
print(message[ : : -3].upper())
Ans : 322ADORSF
21. Find the output of the following
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)
Ans: pYTHOnN#.
22. Write the output of the code given below:
s="C++VsPy"
m=""
for i in range(0, len(s)):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m +s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m +s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m +'&'
print(m)
Ans : c&&vVpP
23. Find the output of the following
def Change(P ,Q=40):
P=P+Q
Q=P-Q
print( P,"#",Q)
return (P)
R=100
S=200
R=Change(R,S)
print(R,"#",S)
S=Change(S)
Ans : 300 # 100
300 # 200
240 # 200