0% found this document useful (0 votes)
36 views

Python Outputs With Solution

Class 12

Uploaded by

vyash6695
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Python Outputs With Solution

Class 12

Uploaded by

vyash6695
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Find Output : 2.

Find and write the output of the following


def fun(s): python code:
k=len(s) def Change(P ,Q=20):
m=" " P=P+Q
for i in range(0,k): Q=P-Q
if (s[i]=='A' or s[i]=='E'):
print( P,"#",Q) return (P)
m+='#'
R=52
elif( s[i].islower()):
S=12
m+=s[i].upper()
else: R=Change(R,S)
m+='X' print(R,"#",S)
print(m) S=Change(S)
fun('Happy NEw YEar 2020')
4. Carefully observe the following python code and
3. Find and write the output of the following python output
code: the following coding
str = “Computer Science” x=5
for i in range(0,len(str),5): def func():
if i%2==0 : global x
print(str[:i].upper(),’$’) x=7
else: print(x)
print (str[i:].lower(),’$’) print(x)
func()
print(x)
5. Find and write the output of the following python 6. Find and write the output of the following python code:
code:
Msg="CompuTer" def Change(P ,Q=20):
Msg1=” “ P=P+Q
for i in range(0, len(Msg)): Q=P-Q
if Msg[i].isupper(): print( P,"#",Q)
return (P)
Msg1=Msg1+Msg[i].lower()
R=67
elif i%2==0:
S=23
Msg1=Msg1+'*' R=Change(R,S)
else: print(R,"#",S)
Msg1=Msg1+Msg[i].upper() S=Change(S)
print(Msg1)
7. What possible outputs are expected to be displayed
on the screen at the time of execution of the program 8. Find and write the output of the following python
from the following code? Also specify the minimum code:
and maximum values that can be assigned to the str = “Computer Science”
variable c. for i in range(0,len(str),5):
import random if i%2==0 :
temp=[10,20,30,40,50,60] print(str[:i].lower(),’$’)
c=random.randint(0,4) else:
for i in range(0, c): print (str[i:].upper,’$’)
print(temp[i],”#”)
(i)10#20# (ii) 10#20#30#40#50#
(iii) 10#20#30# (iv) 50#60#
9. Name the Python Library modules which need to be
imported to invoke the following functions: 10. Find output
(i) plot() print 9//2,9/2, 9/2.0
(ii) randrange()
(iii) log() print 3+3.00,3**3.0
(iv) barh()
print 3**1**3 , 3*1**3
(v) randint()
(vi) float() l=1,23,’hello’,1
(vii) range()
(viii) arange() print type(l)
(ix) pie()
a=(1,2,3)
(x) linspace()
(xi) str() print a*3
11. Consider the following code and determine how 12. def func(alist):
many times statements 1 and 2 will getexecuted? alist=[1,2,3,4]
for a in range (0,7,4): print (alist)
print (a) # statement 1 return
for b in range(0,a+2,2): mylist=[10,20,30]
print(b) #statement 2 func(mylist)
print(mylist)
13. Write the reason / error next to it in comment form. 14. Predict the output of the following programs:
l=[‘a’,’b’,’c’,’d’] x=[1,2,3]
v=6 counter =0
for I in len(l): while counter<len(x):
l[i]+=v print (x[counter]*’%’)
v=v-1 for y in x:
print(“v=”,v,”l=”,l) print (y *’*’)
counter+=1
15. Find the output of the following code:
16. Find output
global x
word =’amazing’
x=5
print word[:4] , word[4:]
def fun2( ):
print word[1:6:2] , word[2:6:2]
x=3
print word[-7:-3,3] , word[::-2]
print(x)
print word[::-1] , word[4:6]
x=x+1
print word[-3:-1] , word[-4:-3]
print(x)
print ord(‘a’),ord(‘z’)
fun2()
print ord(‘a’),ord(‘z’)
On execution ,the above code produces the following output:
print chr(65),chr(90)
6
print chr(97),chr(122)
3
Explain the output with respect to the scope of the variables.
17. Study the following program and write the possible 18. Find Output
output .Also write the Minimum and Maximum value. str="pythonforbeginners is easytolearn"
import random str2="easy"
x= [100,75,10,125] str3="Is"
go= random.randint(0,3) print("the first occurance of str2 is at")
for i in range(go): print(str.find(str2,4))
print(x[i],”$$”) print("the last occurance of str2 is at")
print(str.find(str3))

19. Find Output 20. Predict the outputs of the following programs
def change( ): x=’apple,pear,peach,grapefruit’
L=[] y=x.split(‘,’)
L1=[] for z in y:
L2=[] if z<’m’:
for i in range(1,10): print (str.lower(z))
L.append(i) else:
for i in range(10,1,-2): print (str.upper(z)
L1.append(i)
for i in range(len(L1)):
L2.append(L[i] + L1[i])
L2.append (len (L) - len(L1))
print(L2)
change( )
21. Consider the coding code:
22. How many times will the following for loop
import random
execute and what ‘s the output? Also convert loop
print(100+random.randint(5,10),end=’ ‘)
into while loop
print(100+random.randint(5,10),end=’ ‘)
print(100+random.randint(5,10),end=’ ‘) for i in range (-1,7,-2):
print(100+random.randint(5,10)) for j in range (3):
find the suggest output option (i) to (iv).write the print (i,j)
least value and height value that can be generated
(i) 102 105 104 105 (ii)110 103 104 105
(iii) 105 107 105 110 (iv) 110 105 105 110
1. XAPPYXX#WXX#ARXXXXX
2. (64, '#', 52)
(64, '#', 12)
(32, '#', 12)
>>>
3. ('', '$') 4. 5
('ter science', '$') 7
('COMPUTER S', '$') 7
('e', '$') >>>

5. cO*P*t*R
6. (90, '#', 67)
>>>
(90, '#', 23)
(43, '#', 23)
7. (ii) and (iii) 8. ('', '$')
('TER SCIENCE', '$')
('computer s', '$')
('E', '$')
9. plot() - matplotlib
randrange()- random 10. 4 4 4.5
log() math 6.0 27.0
barh() pyplot
randint() random 33
float() math
<type 'tuple'>
range() Built in function
arange() Built in function of Numpy >>>
pie() matplotlib
linspace() Built in function of Numpy
str() String
11. 0 12. [1, 2, 3, 4]
0 [10, 20, 30]
4 >>>
0
2
4
Statement 1 - 2 times
Statement2 - 4 times
13. l=['a','b','c','d'] 14. %
v=6 *
for i in range (len(l)): **
l[i]+=str(v) ***
print("v=",v,"l=",l) %%
*
output will be **
('v=', 6, 'l=', ['a6', 'b6', 'c6', 'd6']) ***
%%%
*
**
***
>>>
15. 6 16. amaz ing
3 mzn ai
>>> az giaa
gnizama in
in z
97 122
97 122
AZ
az
17. Min value of go 0 18. the first occurance of str2 is at
Max value of go 3 22
Range will be in loop 0-2 the last occurance of str2 is at
125 will never come -1
19. [11, 4, 10, 4, 9, 4, 8, 4, 7, 4] 20. apple
PEAR
PEACH
grapefruit
>>>
21. least value-105 22. for i in range (-1, 7,-2):
last value-110 for j in range (3):
print (i,j)
output (iii) and (iv) no output ( if range is -1,7,-2)

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


for j in range (3):
print (i,j)
9 times(if range is -1,-7,-2)
(-1, 0)
(-1, 1)
(-1, 2)
(-3, 0)
(-3, 1)
(-3, 2)
(-5, 0)
(-5, 1)
(-5, 2)

You might also like