1. Suppose a string S is declared as S = "EXAMINATION", which of the following is incorrect?
a) A = S[2]
b) S[2] = "A"
c) print(S[2])
d) A = len(S)
2. Suppose a string S is declared as S = "ABCD", what is index of character D?
a) 4
b) 0
c) 3
d) 5
3. If the following code is executed, what will be the output of the following code?
name = "PYTHON"
print(name[-3])
a) THON
b) T
c) HON
d) H
4. If the following code is executed, what will be the output of the following code?
name = "ABCDEFGH"
print(name[3:6])
a) DEFG
b) CDE
c) DEF
d) CDEF
5. What is the output of the following code?
txt = "fun with python"
print(txt.title())
a) Fun With Python
b) Fun with python
c) FUN WITH PYTHON
d) fUN wITH pYTHON
6. What is the output of the following code?
txt = "fun with python"
print(txt.find("th",7,14))
a) True
b) 11
c) False
d) 6
7. Write the output of following code.
s = 'Hello@Python'
n = len(s)
m = ''
for i in range(0, n):
if (s[i] >= 'a' and s[i] <= 'm'):
m = m + s[i].upper()
elif (s[i] >= 'n' and s[i] <= 'z'):
m = m + s[i-1]
elif (s[i].isupper()):
m = m + s[i].lower()
else:
m = m + '#'
print(m)
8. Write the output of following code.
string = 'cbse exam 2021'
count = 0
for letter in string:
if letter in 'ae':
count = count + 1
print(count)
9. Write the output of following code.
text = 'ABCD'
number = '1357'
i = 0
s =''
while i < len(text):
s = s + text[i] + number[len(number)-i-1]
i = i + 1
print(s)
10. Write the output of following code.
lower = 'abcdefgh'
upper = 'ABCDEFGH'
num = '12345678'
symbol = '!@#$%^&*'
set1 = lower[0:3]
set2 = upper[6:]
set3 = num[-3:]
set4 = symbol[:-6]
password = set1 + set2 + set3 + set4
print(password)
11. Write the output of following code.
word = 'banana'
if word[0] in "aeiou":
word = word + 'yay'
else:
word = word[1:] + word[0] + 'ay'
print(word)
For Lab Programming Questions click here.