0% found this document useful (0 votes)
27 views22 pages

+2 CS - Output Finding Programs - Answer Key

The document contains a series of Python programming exercises and their corresponding code snippets. Each exercise presents a specific problem or task, along with the expected output or behavior of the code. The exercises cover various programming concepts such as loops, conditionals, functions, and data structures.

Uploaded by

yff6767
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)
27 views22 pages

+2 CS - Output Finding Programs - Answer Key

The document contains a series of Python programming exercises and their corresponding code snippets. Each exercise presents a specific problem or task, along with the expected output or behavior of the code. The exercises cover various programming concepts such as loops, conditionals, functions, and data structures.

Uploaded by

yff6767
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

MOUNT PARK PUBLIC SENIOR SECONDARY SCHOOL

Python Programs
COMPUTER SCIENCE ( 083 )

1. def Findoutput():
L = "First PreBoard"
X = ""
count = 1 1I3s5 7rEBOA13d
for i in L:
if i in ['a', 'e', 'i', 'o', 'u']:
X = X + [Link]()
else:
if count % 2 != 0:
X = X + str(len(L[:count]))
else:
X = X + i
count = count + 1
print(X)
Findouput()

2. tup = ('cold',) (((('cold',), 'cold'), 'hot'), 'cold')


n = 4
for i in range(int(n)):
if i % 2 == 0:
tup = (tup,'cold')
else:
if i > 1:
continue
tup = (tup , 'hot')
print(tup)
3. s = "welcome2kv"
n = len(s) vELCcME#Kk
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)

4. What are the possible outputs ?


import random
AR=[20,30,40,50,60,70] (i) 10#40#70#
FROM=[Link](1,3) (ii) 30#40#50#
TO=[Link](2,4) (iii) 50#60#70#
for K in range(FROM,TO): (iv) 40#50#70#
print (AR[K],end=”#“)

5. def ChangeVal(M, N): def Call(P=40, Q=20):


for i in range(N): P = P + Q
if M[i] % 5 == 0: Q = P - Q
M[i] //= 5 print(P, ‘@’, Q)
if M[i] % 3 == 0: return P
M[i] //= 3 R=200 300@200
L = [25, 8, 75, 12] S=100 300@100
ChangeVal(L, 4) R=call(R,S) 120@100
for i in L: print(R,’@’,S) 300@120
print(i, end="#") S = Call(S)
5#8#5#4# print(R, '@', S)
6. What are the possible outputs ?
import random
Colours = ["VIOLET", "INDIGO", "BLUE", "GREEN", "YELLOW",
"ORANGE", "RED"]
End = [Link](2) + 3
Begin = [Link](End) + 1
for i in range(Begin, End):
print(Colours[i], end="&")

i) INDIGO&BLUE&GREEN& ii) VIOLET&INDIGO&BLUE&


iii) BLUE&GREEN&YELLOW& iv) GREEN&YELLOW&ORANGE&

7. i) def Update(X=10): ii) def update (x=10):


X += 15 global x
print('X = ', X) x+=15
X = 20 print ( x )
Update() x=20
print('X = ', X) update()
print(x)
X=25 35
X=20 35

8. def display(s):
l = len(s)
m = ""
for i in range(0, l):
if s[i].isupper():
m = m + s[i].lower()
elif s[i].isalpha():
m = m + s[i].upper()
elif s[i].isdigit():
m = m + "$"
else:
m = m + "*"
print(m)
display("EXAM2026@[Link]") exam$$$$*CBSE*COM
9. def makenew(mystr):
newstr = " " The new string is : W1L3F5R7W
count = 0
for i in mystr:
if count % 2 != 0:
newstr = newstr + str(count)
else:
if [Link]():
newstr = newstr + [Link]()
else:
newstr = newstr + i
count += 1
newstr = newstr + mystr[:1]
print("The new string is :", newstr)
makenew("WeLlFArE")
10. data=["L",20,"M",40,"N",60] L=[1,2,3,4,5]
times,add=0,0 Lst=[]
alpha="" for i in range(len(L)):
for c in range(1,6,2): if i%2==1:
times = times + c t=(L[i],L[i]**2)
alpha = alpha + data[c-1] + "@" [Link](t)
add = add + data[c] print(Lst)
print(times, add, alpha)
1 20 L@ [(2, 4), (4, 16)]
4 60 L@M@
9 120 L@M@N@
11. data=["L",20,"M",40,"N",60] 9 120 L@M@N@
Times,add=0,0
alpha=""
for c in range(1,6,2):
times = times + c
alpha = alpha + data[c-1] + "@"
add = add + data[c]
print(times, add, alpha)
12. d1={'rno':25, 'name':'dipanshu'}
d2={'name':'himanshu', 'age':30, 'dept':'mechanical'}
[Link](d1)
print([Link]())
print(len(list([Link]())))
dict_keys(['name', 'age', 'dept', 'rno'])
4

13. def foo(s1, s2): def SW (a, b):


l1 = [] if a > b:
l2 = [] print("changed",end="")
for x in s1: return b , a
[Link](x) else:
for x in s2: print("Not",end="")
[Link](x) return a , b
return l1, l2 L = [11, 22, 16, 50, 30]
a, b = foo("FUN", "DAY") for i in range(4, 0, -1):
print(a, b) print(SW(L[i], L[i-1]))
['F', 'U', 'N'] ['D', 'A', 'Y'] Not(30, 50)
changed(16, 50)
Not(16, 22)
changed(11, 22)

14. data = [2,4,2,1,2,1,3,3,4,4]


d = {}
for x in data:
if x in d:
d[x] = d[x] + 1
else:
d[x] = 1
print(d)
{2: 3, 4: 3, 1: 2, 3: 2}
15. i. def change(m, n=10): ii) a = -30
global x def call(x): 5#10@
x += m global a
n += x if a % 2 ==0:
m = n + x x+=a
print(m, n, x) else:
x = 20 x-=a
change(10) return x
change(20) x=20
70 40 30 print(call(35), end="#")
110 60 50 print(call(40), end="@")

16. str = "" What are the possible outputs ?


name = "9@Days" import random
for x in name: M=[5,10,15,20,25,30]
if x in "aeiou": for I in range(1,3):
str += [Link]() F=[Link](2,5)-1
elif not [Link](): S=[Link](3,6)-2
str += "**" T=[Link](1,4)
elif [Link](): print(M[F],M[S],M[T],sep="#")
pass i) 10#25#15 ii) 5#25#25
else: 20#25#25 25#20#15
str += [Link]() iii) 30#20#20 iv) 10#15#25
print(str) **dAys 20#25+25 15#20#10#

17. What are the possible outputs ?


import random i) 66#44#55#
A=[11,22,33,44,55,66]; ii) 33#44#55#
Lower =[Link](1,3) iii) 11#22#33#44#55#
Upper =[Link](2,4) (iv) 33#44#55#11
for P in range(Lower, Upper +1):
print (A[P],end='#')
18. def Change(P ,Q=30): x=["rahul",5, "B",20,30]
P=P+Q [Link](1,3)
Q=P-Q [Link](3, "akon")
print( P,"#",Q) print(x[2])
return (P) 5
R = 150
S = 100
R = Change(R,S) 250 # 150
print(R,"#",S) 250 # 100
S = Change(S) 130 # 100

19. st = "python programming" x = ["A",40,"B",60,"C",20]


count = 4 a,b,c=0,0,0
while True: for I in range(1,6,2):
if st[0] == "p": a+=I
st = st[2:] b+=x[I-1]+’#’
elif st[-2] == "n": c+=x[I]
st = st[:4] print(a,b,c)
else:
count += 1 b=b+x[I-1]+'#'
break TypeError: unsupported operand
print(st) thon type(s) for +: 'int' and 'str'
print(count) 5

20. L=[4,6,7,1,6,9,4] T = (9,18,27,36,45,54)


def fun(L): L=list(T)
for i in range(len(L)): L1=[ ]
if(L[i]%3==0 and L[i]%2==0): for I in L:
L[i]=L[i]+1 if I%6==0:
print(L) [Link](I)
return(L) T1=tuple(L1)
print(L) [4, 6, 7, 1, 6, 9, 4] print(T1)
k=fun(L) [4, 7, 7, 1, 7, 9, 4]
print(k) [4, 7, 7, 1, 7, 9, 4] (18, 36, 54)
21. def checkNumber(N): Enter a number to check: 2
status = N % 2 This is EVEN number
return status
num = int(input("Enter a number to check: "))
k = checkNumber(num)
if k == 0:
print("This is EVEN number")
else:
print("This is ODD number")
22. value = 50 a=20
def display(N): def call():
global value global a
value = 25 b=20
if N%7==0: a=a+b
value = value + N return a
else: print(a)
value = value – N call()
print(value, end="#") print(a)
display(20) 20
print(value) 50#5 40
23. Text1 = "IND-23"
Text2 = ""
I = 0
while I < len(Text1):
if Text1[I] >= "0" and Text1[I] <= "9":
Val = int(Text1[I])
Val = Val + 1
Text2 = Text2 + str(Val)
elif Text1[I] >= "A" and Text1[I] <= "Z":
Text2 = Text2 + Text1[I+1]
else:
Text2 = Text2 + "*"
I += 1
print(Text2) ND-*34
24. text = 'ABCD' A7B5C3D1
number = '1357'
i = 0
s =''
while i < len(text):
s = s + text[i] + number[len(number)-i-1]
i = i + 1
print(s)

25. If n is 9 and then 7, What will be the results of the program


def prime():
n = int(input("Enter number to check :: "))
for i in range(2, n//2 + 1):
if n % i == 0:
print("Number is not prime")
break
else:
print("Number is prime")
prime()

Output : If n = 9 Enter number to check :: 9


Number is not prime
Output : If n = 7 Enter number to check :: 7
Number is prime

26. def Diff(N1,N2): def fact(N):


if N1>N2: fact=1
return N1-N2 while N>0:
else: fact=fact*N
return N2-N1 N=N-1
num=[10,23,14,54,32] print(“F=”,fact
for cnt in range(4,0,-1): fact(7)
a=num[cnt] F=5040
b=num[cnt-1]
print(Diff(a,b),'#',end='') 22 #40 #9 #13 #
27. def modify(L): [2, 26, 23, 18] def Funstr(S): Computer-083#
for C in range(len(L)): T=’’ #083
if C%2==1: for I in S:
L[C]*=2 if [Link]():
else: T= T + I
L[C]//=2 return T
N=[5,13,47,9] A=”Computer-083”
modify(N) B=Funstr(A)
print(N) print(A,'\n',B, sep="#")

28. def ListChange(L): def display(S):


for i in range(len(L)): m=’’
if L[i]%2==0: for I in range(0,len(S)):
L[i]=L[i]*2 if(S[I].isupper()):
if L[i]%3==0: m=m+’*’
L[i]=L[i]*3 elif S[I].islower():
if L[i]%5==0: m=m+’%’
L[i]=L[i]*5 else:
L=[3,4,5,9] if I%2==0:
ListChange(L) m=m+S[i-1]
for i in L: else:
print(i, end="$") m=m+’#’
9$8$25$27$ print(m)
display('Fun@Python3.0')
*%%#*%%%%%n#.
29. What will be the possible outputs :
import random
NAV=[“LEFT”,”FRONT”,”RIGHT”,”BACK”] i. BACKRIGHT
NUM=[Link](1,3) ii. BACKRIGHTFRONT
NAVG=”” iii. BACK
for C in (NUM,1,-1): iv. LEFTFRONTRIGHT
NAVG=NAVG+NAV[C]
print(NAVG) None
30. def fun(a,b): s=’Rs.12’
global x,y n,m=len(s), ‘ ‘
x=a+b for I in range(0,n):
a,y=a+x,a*x if s[i].islower():
print(a,b,x,y) m=m+s[i]
fun(5,10) elif s[i].isupper():
print(fun(b=x,a=y)) m = m +s[i+1]
elif s[i].isdigit():
20 10 15 75 m = m*int(s[i])
165 15 90 6750 else:
None m = '@'+m
print(m) @ss@ss
31. If Y is 8 and then Y is 12, What will be the outputs ?
Y = int(input("Enter 1 or 10: ")) Output : If Y = 8 or 12
if Y == 10: thank you
for Y in range(1, 11): thank you
print(Y) thank you
else: thank you
for m in range(5, 0, -1): thank you
print("thank you")
32. What are the possible outputs for (a) and (b) ?
a) import random
AR = ["MON", "TUE", "WED", "THU", "FRI", "SAT"]
X = [Link](0, 4)
for I in range(1, X+1):
print(AR[I] + "#", end="")
(i) TUE#WED#THU#FRI# (ii) MON#TUE#WED#THU#
(ii) TUE#WED#THU#FRI#SAT# (iv) TUE#WED#

b) import random (i) NX*UA*FM*


TEXT = "EXAMAREFUN" (ii) UM* FA* ER*
COUNT = [Link](0,3) (iii) NA*UM*FA*
C = 9 (iv) EN* XU* AF*
while TEXT[C] != 'E':
print(TEXT[C] + TEXT[COUNT] + '*', end=" ")
COUNT = COUNT + 1
C = C – 1
33. Number = 250 p = 30
while Number <= 1000: for I in range(0,p):
if Number >= 750: if I%4==0:
print(Number) print(I*4)
Number = Number + 10 elif I%5==0:
else: print(I + 3)
print(Number * 2) else:
Number = Number + 50 print(I + 10)
Output : Output :
500 0
600 11
700 12
800 13
900 16
1000 8
1100 16
1200 17
1300 32
1400 19
750 13
760 21
770 48
780 23
790 24
800 18
810 68
820 27
830 28
840 29
850 80
860 31
870 32
880 33
890 96
900 28
910 36
920 37
930 112
940 39
950
960
970
980
990
1000
34. def Convert(Old):
l = len(Old) New string is : iNdiA%****
New = ""
for i in range(0, l):
if Old[i].isupper():
New = New + Old[i].lower()
elif Old[i].islower():
New = New + Old[i].upper()
elif Old[i].isdigit():
New = New + "*"
else:
New = New + "%"
return New
Older = "InDIa@2020"
Newer = Convert(Older)
print("New string is : ", Newer)

35. What are the possible outputs?


import random (i) 10#40#70#
AR=[20,30,40,50,60,70] (ii) 30#40#50#
Lower =[Link](1,4) (iii) 50#60#70#
Upper =[Link](2,5) (iv) 40#50#70#
for K in range(Lower, Upper +1):
print (AR[K],end=”#“)

36. count = 0
while(True): 0 3 6 9 12 15
if count % 3 == 0:
print(count, end = " ")
if(count > 15):
break;
count += 1
37. def encrypt(s):
k = len(s) 0OU34*6OW9
m = ""
for i in range(0, k):
if s[i].isupper():
m = m + str(i)
elif s[i].islower():
m = m + s[i].upper()
else:
m = m + '*'
print(m)
encrypt(“MouNT@TowN”)

38. def fun(s):


k = len(s) cbse#OO#eXAM
m = " "
for i in range(0, k):
if s[i].isupper():
m = m + s[i].lower()
elif s[i].islower():
m = m + s[i].upper()
elif s[i].isdigit():
m = m + "O"
else:
m = m + '#'
print(m)
fun('CBSE@12@Exam')
39. L1 = [100, 900, 300, 400, 500] p,q=8,[8]
START , SUM = 1 , 0 def sum(r, s=5):
for C in range(START, 4): p = r + s
SUM = SUM + L1[C] q = [r, s]
print(C, ":", SUM) print(p, q, sep='@')
SUM = SUM + L1[0] * 10 sum(3, 4)
print(SUM) print(p, q, sep='@')

1 : 900
2 : 2200 7@[3, 4]
3 : 3600 8@[8]
4600

40. def replaceV(st):


newstr = ''
for character in st:
if character in 'aeiouAEIOU':
newstr += '*'
else:
newstr += character
return newstr
st = "Hello how are you"
st1 = replaceV(st)
print("The original String is:", st)
print("The modified String is:", st1)

The original String is: Hello how are you


The modified String is: H*ll* h*w *r* y**
41. def Findoutput():
L = "PreBoard Examination"
X = ""
I1 = []
count = 1
for i in L:
if i in ['a', 'e', 'i', 'o', 'u']:
X = X + [Link]()
else:
if count % 2 != 0:
X = X + str(len(L[:count]))
else:
X = X + i
count = count + 1
print(X)
Findoutput()

1rE3OAr5 7xA9InA11IOn

42. def Show(str):


m = ""
for i in range(0, len(str)):
if str[i].isupper():
m = m + str[i].lower()
elif str[i].islower():
m = m + str[i].upper()
else:
if i % 2 == 0:
m = m + str[i-1]
else:
m = m + "#"
print(m)
Show("GoOdLUcK")

gOoDluCk
43. T = ["20", "50", "30", "40"] def Alpha(N):
Counter = 3 while N:
Total = 0 a=[Link]()
for I in [7, 5, 4, 6]: if a%5>2:
newT = T[Counter] print(a)
Total = float(newT) + I else:
print(Total) break
Counter = Counter – 1 NN=[13,24,12,53,34,42,50]
47.0 Alpha(NN)
35.0 print(NN)
54.0
26.0 [13, 24, 12, 53, 34, 42]

44. T1 = tuple("Amsterdam")
T2, new_list = T1[1:-1], [] [4, 7]
for i in T2:
if i in 'aeiou':
j = [Link](i)
new_list += [j]
print(new_list)

45. x = 25
def modify(s, c=2): W @ 50
global x e # 20
for a in s: 10 $ We
if a in 'QWEiop':
x //= 5
print([Link](),'@',c*x)
else:
x += 5
print([Link](),'#',c+x)
string = 'We'
modify(string,10)
print(x, '$', string)
46. string= ‘abacus@2027’
count=3
while True:
if string[0] == 'a': us@2027
string= string[2:] 4
elif string[-1] == ‘b’:
string =string[:2]
else:
count+= 1
break
print (string)
print(count)

47. F1, F2 , F3 ="WoNdERFUL" , "StuDenTS" , " "


for I in range(0,len(F2)+1):
if F1[I]>='A' and F1<='F': S*u*EnFS*
F3=F3+F1[I]
elif F1[I]>='N' and F1[I]<='Z':
F3=F3+F2[I]
else:
F3=F3+"*"
print(F3)

48. What are the possible outputs?


import random
Cards = ["Heart", "Spade", "Club", "Diamond"]
for i in range(2):
print(Cards[[Link](1, i+2)], end="#")
(A) Spade#Diamond# (B) Spade#Heart#
(C) Diamond#Club# (D) Heart#Spade#
49. def Total (Num=10):
Sum=0
for C in range(1,Num+1):
if C%2!=0: 6$30@
continue
Sum+=C
return Sum
print(Total(4),end="$")
print(Total(),end="@")
50. What are the possible outputs ?
Import random as rd i. 10EXCEL# 10EXCEL# 8OK#
status=[“EXCEL”, “GOOD”, “OK”] ii. 10EXCEL# 8OK# 9GOOD#
turn=10 iii. 10EXCEL# 9GOOD# 10EXCEL#
for count in range(1,4): iv. 10EXCEL# 10GOOD# 8OK
trick=[Link](count)
print(turn-trick,status[trick],end=”#”)
51. Consider the following code and Find the possible outputs :
import random
x=[Link]() i. 0:0 ii. 1:6
y=[Link](0,4) iii. 2:4 iv. 0:3
print(int(x),":",y+int(x))
52. string="aabbcc" K = "FIFA"
count=3 P = [12, 23, 31, 4]
while True: s={}
if string[0]=='a': for I in range(len(K)):
string=string[2:] if I%2==0:
elif string[-1]=='b': S[[Link]()] = K[i]
string=string[:2] else:
else: S[[Link]()] = i + 1
count+=1 for x,y iin [Link]():
break print(x,y,sep=’#’)
print(string) 4 # F
print(count) 3 31 # 2
23 # F
12 # 4
53. What are the possible output will come as result?
import random
List=["Delhi","Mumbai","Chennai","Kolkata"]
for y in range(4):
x = [Link](1,3)
print(List[x],end="#")
a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
54. LST=[5,10,15,20,25,30,35,40,45,50,60,70]
a = randint(3,8) (i) 20#25#25#
b = randint(4,9) (ii) 30#40#70#
c = randint(6,11) (iii) 15#60#70#
print(LST*a+, “#”,LST*b+, “#”,LST*c+, “#”) (iv) 35#40#60#
55. hello = {'empname':"Ishan",'address':"New Delhi",'salary':10000}
hello['salary'] = 15000
hello['address'] = "Delhi"
print([Link]())
print(len([Link]()))
print(tuple([Link]()))
dict_keys(['empname', 'address', 'salary'])
3
('Ishan', 'Delhi', 15000)
56. Original = [10, 20, 30, 40, 50]
Result = {}
while len(Original) > 0: 50:Triple
Val = [Link]() 40:Double
if Val % 20 == 0: 30:Trible
Result[Val] = "Double" 20:Double
else: 10:Trible
Result[Val] = "Triple"
for k, v in [Link]():
print(k, v, sep=":")
57. def fun1():
x = 100
def fun2():
x = 200
print("x in func()2", x)
print("Before calling fun2: " + str(x))
fun2()
print("After calling fun2: " + str(x))
global x
x = 50
fun1()
print("x in main: " + str(x))
Before calling fun2: 100
x in func()2 200
After calling fun2: 100
x in main: 50
58. def fun1():
x = 100
def fun2():
nonlocal x
x = 200
print("x in func()2:", x)
print("Before calling fun2:", x)
fun2()
print("After calling fun2:", x)
x = 50
fun1()
print("x in main:", x)
Before calling fun2: 100
x in func()2: 200
After calling fun2: 200
x in main: 50
59. s="GuDLuck4Xam2026"
n = len(s) gGdlLCK&xAM&&&&
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)

60. a. Name = "PythoN@3.11"


R = ""
for x in range(len(Name)): pYTHOn#@#.1
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)

b. def multiply(numbers):
total = 1 -336
for x in numbers:
total *= x
return total
print(multiply((8, 2, 3, -1, 7)))

You might also like