Page 56 - PYTHON-11
P. 56
(b) word = input("enter the string")
vowels = {'a', 'e', 'i', 'o', 'u'}
d = { }
for i in word:
if i in vowels:
d[i] = d.get(i,0)+1
for k, v in sorted(d.items()):
print(k, "occurred", v, "times")
30. (a) How many types of strings are supported in Python? [3]
Or
(b) What is the difference between (9) and (9,)?
Ans. (a) Python allows two types of strings:
(i) Single Line Strings: These are strings that are terminated in a single line, enclosed within single and
double quotes.
(ii) Multiline Strings: These are strings that store multiple lines of text enclosed within triple single or
double quotes.
Or
(b) When we use type function, then (9) is a type of ‘int’ class whereas (9,) is a type of tuple, which contains
one element.
31. Predict the output of the following code: [3]
d = dict.fromkeys(['x', 'y'], 0)
d['x'] = 10
print(d)
Or
chr = ['X', 'Y', 'Z']
for i in range(len(data)):
print(i, chr[i])
Ans. {'x': 10, 'y': 0}
Or
0 X
1 Y
2 Z
Section D (4 × 4 = 16 Marks)
32. (a) Find the possible outputs of the following Python program. [4]
import random
values = []
for i in range(5):
values.append(random.randrange(1, 6))
print(len(values))
Or
(b) Predict the output of the following code.
str1 = "MachineLearning2025"
result = ""
for i in range(0, len(str1), 6):
result += str1[i]
print(result)
M.5