Output Based Questions In Python Class 11-12 Computer Science
Q 1. Write the output of the following:
for i in '123': print("cbsepython",i,)
Q. 2
for i in [10, 20, 30]: print(i)
Q. 3
for i in range (10,6,-2): print (i* 2)
Q 4.
for i in range (1,5): for j in range (1, i+1): print (i,' ',j)
Q 5.
for x in range (10,20): if (x==15) : break print (x)
Q 6.
for x in range (10,20): if (x%2==0) : continue print (x)
Q 7.
x=50 if x > 10 : if x>25: print("ok") if x > 60 : print ("good") elif x>40: print ("average") else: print ("no output")
Q.8
def Change (P, Q = 30) : P = P + Q Q = P - Q print (P,"@",Q) return P R =150 S= 100 R=Change(R, S) print(R,"@",S) S=Change (S)
Q 9.
Text= "CBSE@python" l = len (Text) ntext=" " for i in range (0,l): if Text[i].isupper(): ntext=ntext +Text[i].lower () elif Text[i].isalpha(): ntext=ntext+Text[i].upper () else: ntext=ntext+'#' print (ntext)
Q 10. How many times is the word ‘Welcome’ printed in the following statement?
s = "python rocks" for ch in s [3:8] : print('Welcome')
Q 11.
word = 'green vegetables' print (word.find ('g',2)) print (word.find ('veg',2)) print (word.find ('tab',4,15))
Q 12.
a = [5, 10, 15, 20, 25] k = 1 i = a[1] + 1 j = a[2] + 1 m = a[k + 1] print (i, j,m)
Q 13.
d ={0: 'a', 1: 'b', 2: 'c'} for i in d: print (4)
Q 14.
x = 123 for i in x: print (i)
Q 15.
strl="helloworld" print(strl[:-1])
Q 16.
print ("xyyzxyzxzxyy".count ('yy',1))
Q. 17
p=10 q=20 p*=q//3 print(p, q)
Q 18.
Str="Computer_Science" Str[-4:] print(Str*2)
Q 19.
x=20 x=x+5 x=x-10 print (x) x, y = x-1,50 print(x, y)
Q 20.
for a in range(3,10,3): for b in range(1,a,2): print(b) print( )
Q 21.
x=10 y=5 for i in range((x-y)*2): print(i)
Q 22.
x="one" y="two" c=0 while c<len(x): print(x[c],y[c]) c=c+1
Q 23.
for i in range(-1,7,2): for j in range(3): print(i,j)
Q 24.
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)
Q 25.
x="hello world" print(x[:2],x[:-2],x[-2:]) print(x[6],x[2:4]) print(x[2:-3],x[-4:-2])
Q 26.
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
Q 27.
def Changer(P,Q=10): P=P/Q Q=P%Q print P,"#",Q return P A=200 B=20 A=Changer(A,B) print A,"$",B B=Changer(B) print A,"$",B A=Changer(A) print A,"$",B
Q 28.
Data = ["P",20,"R",10,"S",30] Times = 0 Alpha = "" Add = 0 for C in range(1,6,2): Times= Times + C Alpha= Alpha + Data[C-1]+"$" Add = Add + Data[C] print Times,Add,Alpha
Q 29.
TXT = ["20","50","30","40"] CNT = 3 TOTAL = 0 for C in [7,5,4,6]: T = TXT[CNT] TOTAL = float (T) + C print TOTAL CNT-=1
Q 30.
line = "Welcome to CBSE PYTHON" L = line.split('e') for i in L: print(i)
Q 31.
p=5/2 q=p*4 r=p+q p+=p+q+r q-=p+q*r print(p,q,r)
Q 32.
a=(2 + 3) ** 3 - 6 / 2 b=(2 + 3) * 5// 4 + (4 + 6) / 2 c=12 + ( 3 * 4 - 6 ) / 3 d=12 % 5 * 3 + (2 * 6) // 4 print(a, b, c, d)