CH2
CH2
6. WAP that:
Prompt the user for a string
Extract all the digits from the string.
If there are digits
Sum the collected digits together.
Printout:
The original string
The digits
The sum of the digits
If there are no digits
Print the original string
A message “Has no Digits”
7. Start with the list[8,9,10]. Do the following using list functions
(a) Set the second entry (index 1) to 17
(b) Add 4, 5 and 6 to the end of the list.
(c) Remove the first entry from the list.
(d) Sort the list.
(e) Double the list.
(f) Insert 25 at index 3.
8. If a is [1, 2, 3], what is the difference (if any) between print( a*3 ) and print [a, a, a]?
9. If a is [1, 2, 3], what is the meaning of a [1:2] = 4 and a [1:1] = 4?
10.Consider L = [ 2 , 4, ,6 , 8, 10] WAP to display the list as [ 4 , 6, , 8, 10 , 2 ]
11.
12.
13.
14.
15.
16. WAP to calculate the mean of the numbers in the given tuple.
17. Write Python script to display the element with minimum value from the given tuple.
18. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for k in d:
print (k, '=', d[k])
19. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for k in d.keys():
print (k, '=', d[k])
20. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for v in d.values():
print (v, end=" ")
21. Write the output of following code:
d = {'x': 1, 'y': 2, 'z': 3}
for v in d.items():
print (v[0], ":", v[1])
22. Write the output of following code:
x = {1:10}
d = {2:20, 3:30, 4:40}
x.update(d)
print(x)
23. consider d = { 1 : [ 10 , 20 , 30] , 2 : [ 40 , 50 , 60 ], 3 : [ 70 , 80 , 90 ] } WAP to display the
keys with its corresponding values’ average.
24. Predict the output :
e = “ Hello Good Morning”
s = e.split(“ “ )
print(s[ : : 3]
25. What will be the output?
numberGames = {}
numberGames[(1,2,4)] = 8
numberGames[(4,2,1)] = 10
numberGames[(1,2)] = 12
sum = 0
for k in numberGames:
sum += numberGames[k]
print len(numberGames) + sum
a) 30 b) 24 c) 33 d) 12
Rough Space