Output Based Questions In Python Class 11-12 Computer Science

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,)

 

('cbsepython', '1')
('cbsepython', '2')
('cbsepython', '3')
>>>

 

 

Q. 2

for i in [10, 20, 30]:
    print(i)

 

10
20
30

 

 

Q. 3

for i in range (10,6,-2):
    print (i* 2)

 

20
16

 

Q 4.

for i in range (1,5):
    for j in range (1, i+1):
        print (i,' ',j)

 

(1, ' ', 1)
(2, ' ', 1)
(2, ' ', 2)
(3, ' ', 1)
(3, ' ', 2)
(3, ' ', 3)
(4, ' ', 1)
(4, ' ', 2)
(4, ' ', 3)
(4, ' ', 4)

 

 

Q 5.

for x in range (10,20):
    if (x==15) :
        break
print (x)

 

15

 

 

Q 6.

for x in range (10,20):
    if (x%2==0) :
        continue
print (x)

 

19

 

 

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")

 

ok

 

 

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)

 

250 @ 150
250 @ 100
130 @ 100

 

 

Q 9. 

Text= "[email protected]"
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)

cbse#PYTHON

 

 

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')

 

5 times

 

Q 11.

word = 'green vegetables'
print (word.find ('g',2))
print (word.find ('veg',2))
print (word.find ('tab',4,15))

8
6
10

 

 

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)

(11, 16, 15)

 

 

 Q 13.

d ={0: 'a', 1: 'b', 2: 'c'}
for i in d:
    print (4)

4
4
4

 

 

Q 14.

x = 123
for i in x:
    print (i)

Error

 

 Q 15. 

strl="helloworld"
print(strl[:-1])

helloworl

 

Q 16. 

print ("xyyzxyzxzxyy".count ('yy',1))

2

 

 

Q. 17

p=10
q=20
p*=q//3
print(p, q)

(60, 20)

 

 

Q 18. 

Str="Computer_Science"
Str[-4:]
print(Str*2)

 

Computer_ScienceComputer_Science

 

 

Q 19. 

x=20
x=x+5
x=x-10
print (x)
x, y = x-1,50
print(x, y)

 

15
(14, 50)

 

 

Q 20.

for a in range(3,10,3):
    for b in range(1,a,2):
        print(b)
    print( )

 

1
()
1
3
5
()
1
3
5
7
()

 

Q 21. 

x=10
y=5
for i in range((x-y)*2):
    print(i)

0
1
2
3
4
5
6
7
8
9

 

 

Q 22. 

x="one"
y="two"
c=0
while c<len(x):
    print(x[c],y[c])
    c=c+1

('o', 't')
('n', 'w')
('e', 'o')

 

Q 23. 

for i in range(-1,7,2):
    for j in range(3):
        print(i,j)

 

(-1, 0)
(-1, 1)
(-1, 2)
(1, 0)
(1, 1)
(1, 2)
(3, 0)
(3, 1)
(3, 2)
(5, 0)
(5, 1)
(5, 2)

 

 

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)

bbcc
4

 

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])

('he', 'hello wor', 'ld')
('w', 'll')
('llo wo', 'or')

 

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

G*L*TME

 

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

10 # 10
10 $ 20
2 # 2
10 $ 2
1 # 1
1 $ 2

 

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

9 60 P$R$S$

 

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

46.0

 

Q 30. 

line = "Welcome to CBSE PYTHON"
L = line.split('e')
for i in L:
    print(i)

W
lcom
to CBSE PYTHON

 

Q 31. 

p=5/2
q=p*4
r=p+q
p+=p+q+r
q-=p+q*r
print(p,q,r)

(22, -94, 10)

 

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)

(122, 11, 14, 9)

 

Leave a Reply

Your email address will not be published. Required fields are marked *