Professional Documents
Culture Documents
[a] TRUE
[b] FALSE
Correct Option:[a]
[a] TRUE
[b] FALSE
Correct Option:[a]
[3] If the condition is evaluated to true, the statement(s) of if block will be executed
[a] TRUE
[b] FALSE
Correct Option:[a]
n=7
c=0
while(n):
if(n>5):
c=c+n-1
n=n-1
else:
Break
print(n)
print(c)
[a] 2
[b] 652
[c] 3
[d] 52
Correct option:[a]
str1=”hello”
c=0
for x in str1:
if(x!=”l”):
c=c+1
else:
Pass
print(c)
[a] 2
[b] 0
[c] 4
[d] 3
3
[6] Which of the following Python code will give different output from the others?
print(i)
print(j)
print(k)
print(l)
Correct option:[c]
str1=”learn python”
str2=””
str3=””
for x in str1:
if(x==”r” or x==”n” or x==”p”):
str2+=x
pass
str3+=x
print(str2,end=” “)
print(str3)
[a] rnpn ea
[b] rnpn ear
[c] rnp ea
[d] rnp ear
Correct Option:[b]
for i in range(0,2,-1):
print(“Hello”)
[a] Hello
5
[b] Hello Hello
[c] No Output
[d] Error
Correct option:[c]
Correct Option:[b]
[10] Which of the following sequences would be generated bt the given line of code?
[a] 5 4 3 2 1 0 -1
[b] 543210
[c] 531
Correct answer:[c]
[a] indefinite
[b] discriminant
[c] definite
[d] indeterminate
Correct answer:[a]
[12] When does the else statement written after loop executes?
7
[b] When loop condition becomes false
Correct Option:[b]
x = “abcdef”
i = “i”
while i in x:
print(i, end=” “)
[a] abcdef
[b] abcdef
[c] i i i i i…..
[d] No Output
correct answer:[d]
[14] What will be the output of the following code?
x = “abcd”
for i in range(len(x)):
print(i)
[a] abcd
[b] 0123
[c] 1234
[d] abcd
Correct Option:[b]
x = 12
for i in x:
print(i)
[a] 12
[b] 12
[c] Error
Correct answer:[c]
9
[16] What will be the output of the following Python code?
i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
[a] 0120
[b] 012
[c] error
Correct Option:[b]
i=0
while i < 3:
print(i)
i += 1
else:
print(0)
[a] 01230
[b] 0120
[c] 012
[d] error
Correct Option:[b]
x = “abcdef”
while i in x:
print(i, end=” “)
[a] abcdef
[b] abcdef
[c] iiiiii…
[d] error
Correct option:[d]
x = “abcdef”
i = “i”
while i in x:
print(i, end=” “)
11
[a] no output
[b] iiiiii…
[c] abcdef
[d] abcdef
Correct option:[a]
x = “abcdef”
i = “a”
while i in x[:-1]:
print(i, end = ” “)
[a] aaaaa
[b] aaaaaa
[c] aaaaaa…
x = “abcdef”
i = “a”
while i in x:
x = x[1:]
print(i, end = ” “)
[a] aaaaaa
[b] a
[c] no output
[d] error
Correct Option:[b]
x = “abcdef”
i = “a”
while i in x[1:]:
print(i, end = ” “)
[a] aaaaaa
[b] a
[c] no output
[d] error
Correct option:[c]
x = 123
for i in x:
13
print(i)
[a] 123
[b] 123
[c] error
Correct option:[c]
for i in d:
print(i)
[a] 012
[b] abc
[c] 0a 1b 2c
Correct option:[a]
print(x, y)
[a] 012
[b] abc
[c] 0a 1b 2c
Correct option:[d]
for x, y in d.items():
print(x, y)
[a] 012
[b] abc
[c] 0a 1b 2c
Correct anser:[C]
15
[27] What will be the output of given Python code?
for x in d.keys():
print(d[x])
[a] 012
[b] abc
[c] 0a 1b 2c
Correct Option:[b]
for x in d.values():
print(x)
[a] 012
[b] abc
[c] 0a 1b 2c
[d] none of the mentioned
Correct Option:[b]
for x in d.values():
print(d[x])
[a] 012
[b] abc
[c] 0a 1b 2c
Correct option:[d]
d = {0, 1, 2}
17
for x in d.values():
print(x)
[a] 012
[c] error
Correct option:[c]
[31] d = {0, 1, 2}
for x in d:
print(x)
[a] 012
[c] error
Correct option:[a]
for x in d:
print(d.add(x))
[a] 012
[b] 012012012…
Correct option:[c]
for i in range(0):
print(i)
[a] 0
[b] no output
[c] error
Correct Option:[b]
19
34 Which of the followings is not a nested loop?
for j in range(1,i+2)
print (i)
for j in range(1,i+2):
print (j)
while j<=i+1:
print (j)
j=j+1
Correct option:b
35 Which of the following statements about the while loop in Python is not true?
Correct option:a
21
a repeat operation(s) many times
b make decisions
correct option:a
a. True
b. False
for i in range(20,0,-2):
print (i)
a) 20
18
16
14
12
10
8
6
4
2
39 What would be the output from the following Python code segment?
x=0
x+=2
print(x)
a.100
b.99
c.101
ans:a
for x in number:
for y in items:
print(x,y):
a 10 chair
23
10table
20 chair
20 table
Answer:a
a) Python’s for loop used to iterates over the items of list, tuple, dictionary, set, or
string
b) else clause of for loop is executed when the loop terminates naturally
c) else clause of for loop is executed when the loop terminates abruptly
d) We use for loop when we want to perform a task indefinitely until a particular
condition is met
ans:a,b,d
a, b = 12, 5
if a + b:
print(‘True’)
else:
print(‘False’)
a) True
b) False
ans: a
a) IF
b) ELSIF
25
c) ELSE
d) CASE
ans:b
a) Bit
b) Std_logic
c) Boolean
d) Integer
Ans:c
ans:a
46 what is output?
if False:
print(“Nissan”)
elif True:
print(“Ford”)
elif True:
print(“BMW”)
27
else:
print(“Audi”)
a) Nissan
b) Ford
C) BMW
d) Audi
Ans:b
a)A comment
b) }
d) end
ans: c
int main()
{
int a=5;
while(a==5)
printf(“RABBIT”);
break;
return 0;
B) RABBIT
C) Compiler error
ans:B
A. list1=[]
B. list1=[]*3
29
C. list1=[2,8,7]
Ans : D
If list1=[6,23,3,2,0,9,8,75]
A. print(list1[1:7:2])
B. print(list1[0:7:2])
C. print(list1[1:8:2])
D. print(list1[0:8:2])
Ans : C
The elements of a list are arranged in descending order.Which of the
51
i. print(list_name.sort())
ii. print(max(list_name))
iii. print(list_name.reverse())
iv. print(list_name[-1])
ans:b
31
A. tuple1=(“a”,”b”)
B. tuple1[2]=(“a”,”b”)
C. tuple1=(5)*2
Ans : A
Ans:B
tuple1=(5,1,7,6,2)
tuple1.pop(2)
print(tuple1)
A. (5,1,6,2)
B. (5,1,7,6)
C. (5,1,7,6,2)
D. Error
Ans : D
Which of the following options will not result in an error when performed on
55
tuples in Python
33
where tupl=(5,2,7,0,3)?
A. tupl[1]=2
B. tupl.append(2)
C. tupl1=tupl+tupl
D. tupl.sort()
Ans:C
tupl=([2,3],”abc”,0,9)
tupl[0][1]=1
print(tupl)
A. ([2,3],”abc”,0,9)
B. ([1,3],”abc”,0,9)
C. ([2,1],”abc”,0,9)
D. Error
Ans:c
57 . Which of the following statements create a dictionary?
a) d = {}
b) d = {“john”:40, “peter”:45}
c) d = {40:”john”, 45:”peter”}
Ans:d
Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command
58
do we use?
a) d.delete(“john”:40)
35
b) d.delete(“john”)
c) del d[“john”]
d) del d(“john”:40)
Answer: c
Answer: b
60 What will be the output of the following Python code snippet?
a={1:”A”,2:”B”,3:”C”}
print(a.get(1,4))
a) 1
b) A
c) 4
Answer: b
37
d) When duplicate keys encountered, the last assignment wins
Answer: c
62 If expression.
a) True
b) Any number
c) Any string
Answer: d
if 79>78:
print( “True”.upcase)
if 9>8:
print( “True”.reverse)
v if 7==7:
print( “equal”.downcase)
a) True
b) True eurt
c) TRUE
eurT
equal
d) equal
Answer: c
a) True
b) False
Answer: a
x=1
if x > 2
39
print(“x is greater than 2”)
print( “x is 1”)
else
a) x is greater than 2
b) x is 1
Answer: b
66 It’s a good habit to give two spaces between if statement and condition.
a) True
b) False
Answer: a
a) When the if condition is false then the next else condition will get executed
b) When the if condition is false then the elsif condition will get executed
c) When the if condition is false and if else condition is true then only it will get
executed
41
d) None of the mentioned
Answer: c
if conditional:
code…
elsif conditional:
code..
else:
code
a) True
b) False
Answer: a
if 1>2:
print( “false”)
else:
print( “True”)
a) False
b) True
c) Syntax error
a) else
b) els
c) if else
Answer: a
a) True
b) False
Answer: b
variable=true
if !variable:
print( “true”)
else:
43
print( “false”)
a) False
b) True
c) Syntax error
Answer: a
a) elseif
b) elif
c) else if
d) elseiff
Answer: b
a) True
b) False
Answer: a
75 The elif statement can add many alternatives to if/else statements.
a) True
b) False
Answer: a
x=7
y=9
if x==y:
print “equal”
elif x>y:
print “greater”
else:
print “less”
a) equal
b) greater
c) less
Answer: c
45
77 What is the output of the given code?
a=true
b=false
if a && b:
print( “False”)
elsif a || b:
print( “True”)
else:
a) false
b) true
Answer: b
a=true
b=false
if a && b:
print( “False”)
elif a || b:
print( “True”)
else:
a) false
b) true
Answer: b
79 Which of I, II, and III below gives the same result as the following nested if?
x = -10
if x < 0:
47
print(“The negative number “, x, ” is not valid here.”)
else:
if x > 0:
else:
print(x, ” is 0″)
I
if x < 0:
else x > 0:
else:
print(x, ” is 0″)
II.
if x < 0:
print(“The negative number “, x, ” is not valid here.”)
elif x > 0:
else:
print(x, ” is 0″)
III.
if x < 0:
if x > 0:
else:
print(x, ” is 0″)
a)I only
b) II only
49
d) All of the above
Answer:b
a)I only
b) II only
a)I only
b) II only
Answer:b
tuple1=(5,1,7,6,2)
tuple1.pop(2)
print(tuple1)
A.(5,1,6,2)
B. (5,1,7,6)
C. (5,1,7,6,2)
D. Error
Ans : D
82
tuple1=(2,4,3)
tuple3=tuple1*2
print(tuple3)
A.(4,8,6)
B. (2,4,3,2,4,3)
C. (2,2,4,4,3,3)
D. Error
Ans : B
51
tupl=(“annie”,”hena”,”sid”)
print(tupl[-3:0])
A. (“annie”)
B. ()
C. None
Ans : B
a) [1, 2, 3]
b) (1, 2, 3)
c) {1, 2, 3}
d) {}
Answer: b
a) print(t[3])
b) t[3] = 45
c) print(max(t))
d) print(len(t))
Answer: b
1. >>>t=(1,2,4,3)
2. >>>t[1:3]
a) (1, 2)
b) (1, 2, 4)
c) (2, 4)
d) (2, 4, 3)
Answer: c
53
1. >>>t = (1, 2, 4, 3, 8, 9)
a) [2, 3, 9]
b) [1, 2, 4, 3, 8, 9]
c) [1, 4, 8]
d) (1, 4, 8)
Answer: c
1. >>>t = (1, 2)
2. >>>2 * t
a) (1, 2, 1, 2)
b) [1, 2, 1, 2]
c) (1, 1, 2, 2)
d) [1, 1, 2, 2]
Answer: a
89 What will be the output of the following Python code?
1. >>>t1 = (1, 2, 4, 3)
2. >>>t2 = (1, 2, 3, 4)
3. >>>t1 < t2
a) True
b) False
c) Error
d) None
Answer: b
1. numberGames = {}
2. numberGames[(1,2,4)] = 8
55
3. numberGames[(4,2,1)] = 10
4. numberGames[(1,2)] = 12
5. sum = 0
6. for k in numberGames:
7. sum += numberGames[k]
a) 30
b) 24
c) 33
d) 12
Answer: c
a) Error
b) None
c) 25
d) 2
Answer: c
92 Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
b) Error
c) 25
Answer: a
Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for
93
slicing operation?
a) print(list1[0])
b) print(list1[:2])
c) print(list1[:-2])
57
d) all of the mentioned
Answer:d
a) list1.shuffle()
b) shuffle(list1)
c) random.shuffle(list1)
d) random.shuffleList(list1)
Answer:c
a) 1
b) 9
c) 15
d) Error
Answer:c
96 suppose list1 is[1,5,9] what is max(list1)?
a) 1
b) 9
c) 15
d) Error
Answer:c
a) 1
b) 9
c) 15
d) Error
Answer:a
print(list1*2)
a)[12,13,14,15]
b)[15,14,13,12]
c)[12,13,14,15,12,13,14,15]
Answer:c
59
99 What is True about datatype list?
Answer:A
print(tuple1*2)
a)(12,13,14,15)
b)(15,14,13,12)
c)[(2,13,14,15,12,13,14,15)
Answer:c
61