File - 995010559 - 1741228460 - Practice Question 7 B
File - 995010559 - 1741228460 - Practice Question 7 B
s="python"
s1=""
s2=""
s3=""
if s[-1]=='n':
s1 = s[0:3]
print(s1)
if 'h' in s:
s2=s[0] + 'i'
print(s2)
if 'z' not in s:
s3 = '7' + s[1:] + 'w'
print(s3)
else:
s = s* 3
print(s)
2. s="python string fun"
while True:
if s[0]=='p':
s = s[3:]
elif s[-1]=='n':
s=s[:2]
else:
break
print(s)
+
Which string method is used to implement the following:
1. To count the number of characters in the string.len()
2. To change the first character of the string in capital letter. Capitilize
3. To check whether given character is letter or a number. isalnum
4. To change lowercase to uppercase letter. Upper()
5. Change one character into another character. replce()
7. Consider the following code :
import math
import random
print(str(int(math.pow(random.randint(2,4),2))), end =" ")
print(str(int(math.pow(random.randint(2,4),2))), end =" ")
print(str(int(math.pow(random.randint(2,4),2))))
What could be the possible outputs out of the given choices, also state the reason
for each option, why :
a) 2 3 4 b) 9 4 4 c) 16 16 16 d) 2 4 9 e) 4 9 4 f) 4 4 4
8.
What type of error is shown by following statement?
>>>t1=(1,2)
>>>t2
A. Value Error B. Type Error C. Name Error D. None of
the above
9.
Predict the output:
a=(1)*3
print(type(a))
a. int b. None c. No output. d. tuple
10.
Consider a declaration L = (1, 'Python', '3.14').
Which of the following represents the data type of L?
a. list
b. tuple
c. dictionary
d. string
11.
Given a Tuple tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90).
What will be the output of print (tup1 [3:7:2])?
a. (40,50,60,70,80)
b. (40,50,60,70)
c. [40,60]
d. (40,60)
12. The return type of the input() function is
a. string
b. integer
c. list
d. tuple
13. Consider a tuple tup1 = (10, 15, 25, and 30). Identify the statement that will result
in an error.
a. print(tup1[2])
b. tup1[2] = 20
c. print(min(tup1))
d. print(len(tup1))
14. What is the output of following code:
T=(100)
print(T*2)
a. Syntax error
b. (200,)
c. 200
d. (100,100)
15.
Find the output of the following :
Text = "gmail@com"
L = len(Text)
nText = ""
for i in range (0,L):
if Text[i].isupper():
nText = nText + Text[i].lower()
elif Text[i].isalpha():
nText = nText + Text[i].upper()
else:
nText = nText + '#&'
print(nText) GMAIL#&COM(Output)
16. Find the output of the following :
word="green vegetables"
print(word.find('g',2)) 8
print(word.find('veg',2)) 6
print(word.find('tab',4,15)) 10
17. Evaluate the following expression and identify the correct answer.
16 - (4 + 2) * 5 + 2**3 * 4
a. 54
b. 46
c. 18
d. 32
18. What will be the output of the following code?
import random
List=["Delhi","Mumbai","Chennai","Kolkata"]
for y in range(4):
x = random.randint(1,3)
print(List[x],end="#")
a. Delhi#Mumbai#Chennai#Kolkata#
b. Mumbai#Chennai#Kolkata#Mumbai#
c. Mumbai# Mumbai #Mumbai # Delhi#
d. Mumbai# Mumbai #Chennai # Mumbai
19. Predict the output of the following code snippet :
x="hello world"
print(x[:2],x[:-2],x[-2:])
print(x[2:-3],x[-4:-2])
20.
Find the output:
mystr="sTUdeNT"
newstr = ""
count = 0
for i in mystr:
if count%2 != 0:
newstr = newstr + str(count)
elif i.islower():
newstr = newstr + i.upper()
else:
newstr = newstr + i
count += 1
newstr = newstr + mystr[:1]
print("The new string is:", newstr)
21.
Find the output of the following Python code :
for Subject in [‘Physics’,’Chemistry’,’Mathematics’,’English’]:
print(Subject)
if Subject[0]==’M’
break
else:
print(‘Compulsory’)
print(‘Optional’)
22.
What are the possible outcome(s) executed from the following code ? Also
specify the maximum and minimum values that can be assigned to variable
PICKER.
import random
PICKER = random randint (0, 3)
COLOR [‘Blue’,’Pink’,’Green’,’Red’]
for I in COLOR :
for J in range (1, PICKER):
Print (I, end = ‘;’)
Print ()
23. myString = "ijk"
stringList = ["abc", "ijk", "xyz"]
print(stringList[1] == myString)
print(stringList[1] is myString)
24. Which of the following number of iterations won’t be printed when this Python
code is run?
if letter == 'h':
continue
29.
Find the output: The new string is:
mystr="wElCo#Me" W1EL3CO5#M7Ew
newstr = ""
count = 0
for i in mystr:
if count%2 != 0:
newstr = newstr + str(count)
if i.islower():
newstr = newstr + i.upper()
else:
newstr = newstr + i
count += 1
newstr = newstr + mystr[:1]
print("The new string is:", newstr)
30. ccc
31.
32. Which of these Python data structures cannot have duplicate items and does not support
ordering?
a. list
b. tuple
c. dictionary
d. set
33.
Find the output:
mystr="HARMONIOUS"
L = len(mystr)
str2=''
str3=''
for i in range(0,L,2):
str2=str2 + mystr[i+1]+mystr[i]
for ch in str2:
if ch>='R' and ch<='U':
str3+='$'
else:
str3+=ch.lower()
print(str3)
print(mystr)
34.
35.