Python Outputs With Solution
Python Outputs With Solution
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)