WORKSHEET Revision
WORKSHEET Revision
8.Choose the best option for the possible output of the following code
import random
L1=[random.randint(0,10) for x in range(3)]
print(L1)
(a) [0,0,7] (b) [9,1,7] (c) [10,10,10] (d) All are possible
9.import random
num1=int(random.random()+0.5)
What will be the minimum and maximum possible values of variable num1
10. What possible output(s) will be obtained when the following code is executed
import random
k=random.randint(1,3)
fruits=[‘mango’, ‘banana’, ‘grapes’, ‘water melon’, ‘papaya’]
for j in range(k):
print(j, end=“*”)
(a) mango*banana*grapes (b) banana*grapes
(c) banana*grapes*watermelon (d) mango*grapes*papaya
11.8.Write a Program in Python, that takes the dictionary as an input from user
And create a new dictionary containing the details of only those events which are seminars.
For example, consider the following
dictionary
events={‘Delhi’:‘seminar’, ‘Mumbai’:‘Party’,
‘Dehradun’:‘Marriage’, ‘Goa’:‘seminar’}
The new dictionary should contain:
{‘Delhi’:‘seminar’, ‘Goa’:‘seminar’}
12.9.Write a program that takes a string and create a dictionary containing the count of each
article.
For example if the string is ‘The logical or is an operator not
a literal or a punctuator. ’
The resultant dictionary will have
{‘The’:1, ‘an’:1, ‘a’:2}
13. Write a Program in Python, that takes the dictionary and displays the subjects (in upper
case) for which marks is greater than or equal to 75.
For example, consider the following dictionary
marks = {‘eng’:78, ‘phy’:69, ‘chem’:74, ‘math’:75,
‘cs’:84}
The output should be:
ENG MATH CS
14.Write a program that takes a string and create a dictionary containing count of each letter
in String.
For example, if the String is ‘Peter Parker’
The dictionary will have
{‘P’:2, ‘e’:3, ‘t’:1, ‘r’:3, ‘ ’:1, ‘a’:1, ‘k’:1}
15. Write a program in Python to replaces elements having even values with its half and
elements having odd values with twice its value in a list.
eg: if the list contains 3,4,5,16,9 then rearrange the list as 6,2,10,8,18