0% found this document useful (0 votes)
12 views61 pages

PPS MCQs Unit 1-4

Uploaded by

knetam11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views61 pages

PPS MCQs Unit 1-4

Uploaded by

knetam11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

PPS Unit 1-4 MCQs

For SPPU Syllabus - Semester 1

UNIT 1 - Problem Solving, Programming and


Python Programming
UNIT 2 - Decision Control Statements
UNIT 3 - Functions and Modules
UNIT 4 - Strings

For more MCQs join SPPU Engineers


SINHGAD COLLEGE OF ENGINEERING,PUNE-41
Department of Engineering Science
Class-FE Unit no:I
Subject Name : Programming and Problem Solving

Sr. Correct
Question Option1 Option2 Option3 Option4
No. Option
What is the maximum possible length of an
1 32 8 16 None of these these None of these
identifier?
Guido van
2 Who developed the Python language? Guido van Rossum Niene Stom Zim Den Wick van Rossum
Rossum
3 In which year Python language developed? 1980 1995 1981 1989 1980
4 In which language Python is written? PHP English C All of the above C
Which one of the following is the correct
5 .py .python .p None of these these .py
extension of the Python file?
In which year was the Python 3.0 version
6 2000 2008 2010 2005 2008
developed?
What do we use to define a block of code in
7 Brackets Key Indentation d. None of these Indentation
Python language?
Which character is used in Python to make a
8 // / # ! #
single line comment?
stepwise
Top down design strategy is also known as: stepwise refinement output module input module none of above
refinement
10 string is collection of character numbers operators none of above character
infix
11 Types of expressions are infix expression outfix expression postfix expression a and c
expression
analysis and analysis and
12 A design is an intermediate sep between coding and testing testing and maintenance none of above
coding coding
13 How many types of problems in Python 1 2 3 4 2
Which of the following declarations is
14 __x = 3 _x=2 __xyz__ = 5 None of these None of these
incorrect?
Which of the following is not a keyword in
15 raise val try with val
Python language?
Which of the following operators is the correct
16 a**b a^b a^^b a^*b a**b
option for power(ab)?

Join Telegram @SPPUBtech


17 The sequence of solutions to the problems is logical not logical a and b none of these logical
One of the most difficult task for the problem writing the reading the writing the
18 solving the instruction d. None of these
solver is instructions instruction instructions
zero of one
19 Each algorithm is supplied with zero of one input two input three input four input
input
Flowcharts are the --------- representation of
20 graphical non graphical a and b none of these graphical
algorithms.
input and
21 The parallelogram indicates input and output only input only output b and c
output
one entrance and one entrance
22 The diamond indicates the decision and it has two entrance three exits a and b
two exits and two exits
one entrance and one entrance and one entrance
23 The process module has no exits b and c
one exit two exits and one exit
two different two different
24 The on page connector connects the section on the same on different page multiple pages a and b section on the
page same page
two different two different
25 The off page connector connects the section on different three sections four sections infinite section section on
pages different pages
For large and complex programs,designing of
26 complicated easy heuristic all the above Easy
flowchart becomes
For large and complex programs,designing of
27 complicated easy heuristic all the above Complecated
Algorithm becomes
formal
28 Programming languages are formal language informal language a and b none of these
language
procedural procedural
29 The imperative programming is also called as non procedural sequential programming a and c
programming programming
30 Examples of imperative programming are C Pascal Ada, Fortran all above C
In object oriented programming language
31 object class entity a and b object
everything is modelled as
32 Examples of OOP are smalltalk C++ java, python all the above all of above
33 A problem is a _____of difficulty state alternatives nature none of these state
For solving some problem which actions are series of
34 predicted actions series of actions popular actions a and b
taken actions

Join Telegram @SPPUBtech


The solution that can not be reached through heuristic
35 indirect solution direct solution heuristic solution a and c
direct set of steps are called solution
Coding is a step in which design is translated machine readable machine
36 non-readable form static form dynamic form
into______ form readable form
37 Testing begins when____is done coding designing maintenance b and c coding
at least one
38 Each algorithm must produce at least two output at least one output at least three output at least four output
output
procedural non procedural procedural
39 The imperative programming is also called as iterative programming a and b
programming programming programming
data and methods are bound in one entity
40 object class inheritance interface object
called
41 The logic paradigm focuses on non predicate logic alternative logic predicate logic a and b predicate logic
__is another field in which python has a
42 networking programming designing none of these networking
brighter scope in the future
cannot be
43 A constant is a type of variable whose value can be changed cannot be changed a and b none of these
changed
44 Boolean literal has two values left and right up and down none of these true and false true and false
45 Variable name should not start with lower case letters uppercase letters numbers a and b Numbers
46 Tuple is a collection of array string elements b and c elements
stop writing a start writing a start writing a
47 We use hash (#) symbol to null none of these
comment comment comment
Leading white space at the beginning of logical
48 indentation intention carrying forwarding indentation
line is called
49 list is collection of Numbers Characters Floating Values All of Above all of above
50 Each algorithm should have finiteness infiniteness null a and b finiteness

Join Telegram @SPPUBtech


SINHGAD COLLEGE OF ENGINEERING
Department of Information Technology
Programming and Problem Solving (110005)
UNIT-II- Decision Control Statements
Multiple choice questions Bank

Content:
Decision Control Statements: Decision control statements, Selection/conditional branching
Statements: if, if-else, nested if, if-elif-else statements. Basic loop Structures/Iterative statements:
while loop, for loop, selecting appropriate loop. Nested loops, The break, continue, pass, else
statement used with loops. Other data types- Tuples, Lists and Dictionary.

1. Which of the following is not used as loop in Python?

A. for loop
B. while loop
C. do-while loop
D. None of the above
Answer: C

2. Which of the following is False regarding loops in Python?

A. Loops are used to perform certain tasks repeatedly.


B. While loop is used when multiple statements are to executed repeatedly until the given
condition becomes False
C. While loop is used when multiple statements are to executed repeatedly until the given
condition becomes True.
D. for loop can be used to iterate through the elements of lists.
Answer: B

3. Which of the following is True regarding loops in Python?

A. Loops should be ended with keyword "end".


B. No loop can be used to iterate through the elements of strings.
C. Keyword "break" can be used to bring control out of the current loop.
D. Keyword "continue" is used to continue with the remaining statements inside the loop.
Answer: C

4. How many times will the loop run?


i=2
while(i>0):
i=i-1
A. 2
B. 3
C. 1
D. 0
Answer: A

Join Telegram @SPPUBtech


5. What will be the output of the following Python code?

list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
sum = 0
sum1 = 0
for elem in list1:
if (elem % 2 == 0):
sum = sum + elem
continue
if (elem % 3 == 0):
sum1 = sum1 + elem
print(sum , end=" ")
print(sum1)

A. 8 9
B. 8 3
C. 2 3
D. 8 12
Answer: D

6. Which one of the following is a valid Python if statement

A. if a>=2 :
B. if (a >= 2)
C. if (a => 22)
D. if a >= 22
Answer: A

7. What keyword would you use to add an alternative condition to an if statement?

A. else if
B. elseif
C. elif
D. None of the above
Answer: C

8. Can we write if/else into one line in python?

A. Yes
B. No
C. if/else not used in python
D. None of the above
Answer: A

9. In a Python program, a control structure:

A. Defines program-specific data structures


B. Directs the order of execution of the statements in the program
Join Telegram @SPPUBtech
C. Dictates what happens before the program starts and after it terminates
D. None of the above
Answer: B

10. What will be output of this expression?


'p' + 'q' if '12'.isdigit() else 'r' + 's'

A. pq
B. rs
C. pqrs
D. pq12
Answer: A

11. Which statement will check if a is equal to b?

A. if a = b:
B. if a == b:
C. if a === c:
D. if a == b
Answer: B

12. Does python have switch-case statement?

A. True
B. False
C. Python has switch statement but we cannot use it.
D. None of the above
Answer: B

13. What will be the output of given Python code?


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. 6 5 2
C. 3
D. 5 2
Answer: A

Join Telegram @SPPUBtech


14. What will be the output of given Python code?

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
Answer: D

15. Which of the following Python code will give different output from the others?

A. for i in range(0,5):
print(i)
B. for j in [0,1,2,3,4]:
print(j)
C. for k in [0,1,2,3,4,5]:
print(k)
D. for l in range(0,5,1):
print(l)
Answer: C

16. What will be the output of the following Python code?


str1="learn python"
str2=""
str3=""
for x in str1:
if(x=="r" or x=="n" or x=="p"):
str2+=x
pass
if(x=="r" or x=="e" or x=="a"):
str3+=x
print(str2,end=" ")
print(str3)

A. rnpn ea
B. rnpn ear
C. rnp ea
D. rnp ear
Answer: B

17. What will be the output of the following Python code?


for i in range(0,2,-1):
print("Hello")

Join Telegram @SPPUBtech


A. Hello
B. Hello Hello
C. No Output
D. Error
Answer: C

18. Which of the following is a valid for loop in Python?

A. for(i=0; i < n; i++)


B. for i in range(0,5):
C. for i in range(0,5)
D. for i in range(5)
Answer: B

19. Which of the following sequences would be generated bt the given line of code?
range (5, 0, -2)

A. 5 4 3 2 1 0 -1
B. 5 4 3 2 1 0
C. 5 3 1
D. None of the above
Answer: C

20. A while loop in Python is used for what type of iteration?

A. indefinite
B. discriminant
C. definite
D. indeterminate
Answer: A

21. When does the else statement written after loop executes?

A. When break statement is executed in the loop


B. When loop condition becomes false
C. Else statement is always executed
D. None of the above
Answer: B

22. What will be the output of the following code?


x = "abcdef"
i = "i"
while i in x:
print(i, end=" ")

A. a b c d e f
B. abcdef
C. i i i i i.....
D. No Output
Answer: D

Join Telegram @SPPUBtech


23. What will be the output of the following code?
x = "abcd"
for i in range(len(x)):
print(i)

A. abcd
B. 0 1 2 3
C. 1 2 3 4
D. a b c d
Answer: B

24. What will be the output of the following code?


x = 12
for i in x:
print(i)

A. 12
B. 1 2
C. Error
D. None of the above
Answer: C

25. What does the following code print to the console?


if 2 == 2:
print("ice cream is tasty!")

A. No output
B. ice cream
C. "ice cream is tasty!"
D. None of the above
Answer: C

26. What does the following code print to the console?


if "cat" == "dog":
print("prrrr")
else:
print("ruff")
"ruff" is printed.

A. prrrr
B. ruf
C. prrrrruff
D. None of the above
Answer: B

Join Telegram @SPPUBtech


27. What does the following code print to the console?
if 5 > 10:
print("fan")
elif 8 != 9:
print("glass")
else:
print("cream")
"glass" is printed.

A. fan
B. cream
C. glass
D. None of the above
Answer: C

28. What does the following code print to the console?


name = "maria"
if name == "melissa":
print("usa")
elif name == "mary":
print("ireland")
else:
print("colombia")

A. ireland
B. maria
C. usa
D. colombia
Answer: D

29. What does the following code print to the console?


if 88 > 100:
print("cardio")

A. error
B. cardio
C. No output
D. None of the above
Answer: C

30. What does the following code print to the console?


hair_color = "blue"
if 3 > 2:
if hair_color == "black":
print("You rock!")
else:
print("Boring")
A. Boring
B. You rock!
C. black
D. None of the above
Answer: A
Join Telegram @SPPUBtech
31. What does the following code print to the console?
if True:
print(101)
else:
print(202)

A. 201
B. 101201
C. 101
D. error
Answer: C

32. What does the following code print to the console?


if False:
print("Nissan")
elif True:
print("Ford")
elif True:
print("BMW")
else:
print("Audi")
"Ford" is printed

A. BMW
B. Ford
C. Nissan
D. Audi
Answer: B

33.What does the following code print to the console?


if 0:
print("huh?")
else:
print("0 is falsy!")
0 is falsy is printed.

A. huh?
B. 0 is falsy
C. huh? 0 is falsy
D. No Output
Answer: B

34. What does the following code print?

if 4 + 5 == 10:
print("TRUE")
else:
print("FALSE")
print("TRUE")

Join Telegram @SPPUBtech


A. TRUE
B.
TRUE
FALSE
C.
FALSE
TRUE
D.
TRUE
FALSE
TRUE
Answer: A

35. Which of the following is true about the code below?

x=3
if (x > 2):
x = x * 2;
if (x > 4):
x = 0;
print(x)

A. x will always equal 0 after this code executes for any value of x
B. if x is greater than 2, the value in x will be doubled after this code executes
C. if x is greater than 2, x will equal 0 after this code executes
D. None of the Above
Answer: C

36. What is the total for 12 items that weigh 3 pounds?


weight = 0.5
numItems = 5
if weight < 1:
price = 1.45
if weight >= 1:
price = 1.15
total = weight * price
if numItems >= 10:
total = total * 0.9
print(weight)
print(price)
print(total)

A. $3.45
B. $3.11
C. $3.105
D. $3.10
Answer: C

Join Telegram @SPPUBtech


37. Given two variables, num1 and num2, which of the following would mean that both num1 and num2
are positive integers?

A. (num1 = num2)
B. (num1 = num2) OR (num1 ≠ num2)
C. (num1 = num2) AND (num1<0)
D. (num1 = num2) AND (num2>0)
Answer: D

38. What will be the output of the following Python code?


x = ['ab', 'cd']
for i in x:
x.append(i.upper())
print(x)

A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’, ‘AB’, ‘CD’]
C. [‘ab’, ‘cd’]
D. none of the mentioned
Answer: D

39. What will be the output of the following Python code?


i=1
while True:
if i%3 == 0:
break
print(i)
i+=1

A. 1 2
B. 1 2 3
C. error
D. none of the mentioned
Answer: C

40. What will be the output of the following Python code?


i=1
while True:
if i%0O7 == 0:
break
print(i)
i += 1

A. 1 2 3 4 5 6
B. 1 2 3 4 5 6 7
C. error
D. none of the mentioned
Answer: A

Join Telegram @SPPUBtech


41. What will be the output of the following Python code?
True = False
while True:
print(True)
break

A. True
B. False
C. None
D. none of the mentioned
Answer: D

42. What will be the output of the following Python code?


i=0
while i < 3:
print(i)
i += 1
else:
print(0)

A. 0 1 2 3 0
B. 0 1 2 0
C. 0 1 2
D. error
Answer: B

43. What will be the output of the following Python code?


x = "abcdef"
i = "a"
while i in x:
print('i', end = " ")

A. no output
B. i i i i i i …
C. a a a a a a …
D. a b c d e f
Answer: B

44. What will be the output of the following Python code?


x = "abcdef"
i = "a"
while i in x:
x = x[:-1]
print(i, end = " ")

A. i i i i i i
B. a a a a a a
C. a a a a a
D. none of the mentioned
Answer: B

Join Telegram @SPPUBtech


45. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
x = x[1:]
print(i, end = " ")

A. a a a a a a
B. a
C. no output
D. error
Answer: B

46. What will be the output of the following Python code?


x = "abcdef"
i = "a"
while i in x[1:]:
print(i, end = " ")

A. a a a a a a
B. a
C. no output
D. error
Answer: C

47. What will be the output of the following Python code?


x = 'abcd'
for i in x:
print(i)
x.upper()

A. a B C D
B. a b c d
C. A B C D
D. error
Answer: B

48. What will be the output of the following Python code?


x = 'abcd'
for i in x:
print(i.upper())

A. a b c d
B. A B C D
C. a B C D
D. error
Answer: B

49. What will be the output of the following Python code?


x = 'abcd'
for i in range(x):
print(i)
Join Telegram @SPPUBtech
A. a b c d
B. 0 1 2 3
C. error
D. none of the mentioned
Answer: C

50. What will be the output of the following Python code?


x = 'abcd'
for i in range(len(x)):
print(i)

A. a b c d
B. 0 1 2 3
C. error
D. 1 2 3 4
Answer: B

Join Telegram @SPPUBtech


1. Which of the following is the use of function in python?
a) Functions are reusable pieces of programs
b) Functions don’t provide better modularity for your application
c) you can’t also create your own functions
d) All of the mentioned
Answer: a
2. Which keyword is used for function?
a) Fun
b) Define
c) Def
d) Function
Answer: c
3. What will be the output of the following Python code?
1. def sayHello():
2. print('Hello World!')
3. sayHello()
4. sayHello()

a)
Hello World!
Hello World!
b)
'Hello World!'
'Hello World!'
c)
Hello
Hello
d) None of the mentioned

Join Telegram @SPPUBtech


Answer: a

4. What will be the output of the following Python code?


1. def printMax(a, b):
2. if a > b:
3. print(a, 'is maximum')
4. elif a == b:
5. print(a, 'is equal to', b)
6. else:
7. print(b, 'is maximum')
8. printMax(3, 4)
a) 3
b) 4
c) 4 is maximum
d) None of the mentioned
Answer: c
5. What will be the output of the following Python code?
1. x = 50
2. def func(x):
3. print('x is', x)
4. x = 2
5. print('Changed local x to', x)
6. func(x)
7. print('x is now', x)
a)
x is 50
Changed local x to 2
x is now 50
b)
x is 50
Changed local x to 2
x is now 2

Join Telegram @SPPUBtech


c)
x is 50
Changed local x to 2
x is now 100
d) None of the mentioned
Answer: a
6. What will be the output of the following Python code?
1. x = 50
2. def func():
3. global x
4. print('x is', x)
5. x = 2
6. print('Changed global x to', x)
7. func()
8. print('Value of x is', x)
a)
x is 50
Changed global x to 2
Value of x is 50
b)
x is 50
Changed global x to 2
Value of x is 2
c)
x is 50
Changed global x to 50
Value of x is 50
d) None of the mentioned
Answer: b
7. What will be the output of the following Python code?

Join Telegram @SPPUBtech


1. def say(message, times = 1):
2. print(message * times)
3. say('Hello')
4. say('World', 5)
a)
Hello
WorldWorldWorldWorldWorld
b)
Hello
World 5
c)
Hello
World,World,World,World,World
d)
Hello
HelloHelloHelloHelloHello
Answer: a
8. What will be the output of the following Python code?
1. def func(a, b=5, c=10):
2. print('a is', a, 'and b is', b, 'and c is', c)
3.
4. func(3, 7)
5. func(25, c = 24)
6. func(c = 50, a = 100)
a)
a is 7 and b is 3 and c is 10
a is 25 and b is 5 and c is 24
a is 5 and b is 100 and c is 50
b)
a is 3 and b is 7 and c is 10
a is 5 and b is 25 and c is 24

Join Telegram @SPPUBtech


a is 50 and b is 100 and c is 5
c)
a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
a is 100 and b is 5 and c is 50
d) None of the mentioned
Answer: c
9. What will be the output of the following Python code?
1. def maximum(x, y):
2. if x > y:
3. return x
4. elif x == y:
5. return 'The numbers are equal'
6. else:
7. return y
8.
9. print(maximum(2, 3))
a) 2
b) 3
c) The numbers are equal
d) None of the mentioned
Answer: b
10. Which of the following is a feature of DocString?
a) Provide a convenient way of associating documentation with Python modules,
functions, classes, and methods
b) All functions should have a docstring
c) Docstrings can be accessed by the __doc__ attribute on objects
d) All of the mentioned
Answer: d
11. Which are the advantages of functions in python?

Join Telegram @SPPUBtech


a) Reducing duplication of code
b) Decomposing complex problems into simpler pieces
c) Improving clarity of the code
d) All of the mentioned
Answer: d
12. What are the two main types of functions?
a) Custom function
b) Built-in function & User defined function
c) User function
d) System function
Answer: b
13. Where is function defined?
a) Module
b) Class
c) Another function
d) All of the mentioned
Answer: d
14. What is called when a function is defined inside a class?
a) Module
b) Class
c) Another function
d) Method
Answer: d
15. Which of the following is the use of id() function in python?
a) Id returns the identity of the object
b) Every object doesn’t have a unique id
c) All of the mentioned

Join Telegram @SPPUBtech


d) None of the mentioned
Answer: a
16. Which of the following refers to mathematical function?
a) sqrt
b) rhombus
c) add
d) rhombus
Answer: a
17. What will be the output of the following Python code?
1. def cube(x):
2. return x * x * x
3. x = cube(3)
4. print x
a) 9
b) 3
c) 27
d) 30
Answer: c
18. What will be the output of the following Python code?
1. def C2F(c):
2. return c * 9/5 + 32
3. print C2F(100)
4. print C2F(0)
a)
212
32
b)
314
24
c)

Join Telegram @SPPUBtech


567
98
d) None of the mentioned
Answer: a
19. What will be the output of the following Python code?

1. def power(x, y=2):


2. r = 1
3. for i in range(y):
4. r=r*x
5. return r
6. print power(3)
7. print power(3, 3)
a)
212
32
b)
9
27
c)
567
98
d) None of the mentioned
Answer: b
20. What will be the output of the following Python code?
1. def sum(*args):
2. '''Function returns the sum
3. of all values'''
4. r = 0
5. for i in args:
6. r += i
7. return r
8. print sum.__doc__

Join Telegram @SPPUBtech


9. print sum(1, 2, 3)
10. print sum(1, 2, 3, 4, 5)

a)
6
15
b)
6
100
c)
123
12345
d) None of the mentioned
Answer: a
21. Python supports the creation of anonymous functions at runtime, using a construct
called __________
a) lambda
b) pi
c) anonymous
d) none of the mentioned
Answer: a
22. What will be the output of the following Python code?
1. y = 6
2. z = lambda x: x * y
3. print z(8
a) 48
b) 14
c) 64
d) None of the mentioned

Join Telegram @SPPUBtech


Answer: a
23. What will be the output of the following Python code?
1. lamb = lambda x: x ** 3
2. print(lamb(5))
a) 15
b) 555
c) 125
d) None of the mentioned
Answer: c
24. Does Lambda contains return statements?
a) True
b) False
Answer: b
25. Lambda is a statement.
a) True
b) False
Answer: b
26. Lambda contains block of statements.
a) True
b) False
Answer: b
27. What will be the output of the following Python code?
1. def f(x, y, z): return x + y + z
2. f(2, 30, 400

a) 432
b) 24000
c) 430

Join Telegram @SPPUBtech


d) No output
Answer: a
28. What will be the output of the following Python code?
1. def writer():
2. title = 'Sir'
3. name = (lambda x:title + ' ' + x)
4. return name
5.
6. who = writer()
7. who('Arthur')
a) Arthur Sir
b) Sir Arthur
c) Arthur
d) None of the mentioned
Answer: b
29. What will be the output of the following Python code?
1. L = [lambda x: x ** 2,
2. lambda x: x ** 3,
3. lambda x: x ** 4]
4.
5. for f in L:
6. print(f(3))
a)
27
81
343
b)
6
9
12
c)
9

Join Telegram @SPPUBtech


27
81
d) None of the mentioned
Answer: c
30. What will be the output of the following Python code?
1. min = (lambda x, y: x if x < y else y)
2. min(101*99, 102*98)

a) 9997
b) 9999
c) 9996
d) None of the mentioned
Answer: c
31. What is a variable defined outside a function referred to as?
a) A static variable
b) A global variable
c) A local variable
d) An automatic variable
Answer: b
32. What is a variable defined inside a function referred to as?
a) A global variable
b) A volatile variable
c) A local variable
d) An automatic variable
Answer: c

Join Telegram @SPPUBtech


UNIT-IV STRINGS

Multiple Choice Questions

Q-1: What is printed by the following statements?

s = "python rocks"
print(s[1] * s.index("n"))
A. yyyyy
B. 55555
C. n
D. Error, you cannot combine all those things together.

Ans-D

Q-2: What will be printed when the following executes?

str = "His shirt is red"


pos = str.find("is")
print(pos)
A. 1
B. 9
C. 10
D. 6

Ans-A

Q-3: What will be printed when the following executes?

str = "This is the end"


str = str[5]
print(str)
A. i
B. s
C. is the end
D. t

Ans-A

Q-4: What is the value of s1 after the following code executes?

s1 = "HEY"
s2 = s1.lower()
s3 = s2.capitalize()
A. Hey
B. hey
C. HEY
D. HEy

Join Telegram @SPPUBtech


Ans- C

Q-5: What would the following code print?

Mali = 5
print("Mali" + " is " + str(Mali))
A. Mali is Mali
B. Mali is 5
C. 5 is Mali
D. 5 is 5

Ans- B

Q-6: What is printed by the following statements?

s = "python rocks"
print(s[3])
A. t
B. h
C. c
D. Error, you cannot use the [ ] operator with a string.

Ans- B

Q-7: What is printed by the following statements?

s = "python rocks"
print(s[2] + s[-5])
A. tr
B. ps
C. nn
D. Error, you cannot use the [ ] operator with the + operator.

Ans-A

Q-8: What is printed by the following statements?

s = "python rocks"
print(len(s))

A. 11
B. 12
C. 10
D. 7

Ans-B

Join Telegram @SPPUBtech


Q-9: What is printed by the following statements:

s = "Rose"
s[1] = "i"
print(s)

A. Rose
B. Rise
C. Error
D. Rsoe

Ans-C

Q-10: What is printed by the following statements:

s = "ball"
r = ""
for item in s:
r = item.upper() + r
Print(r)

A. Ball
B. BALL
C. LLAB
D. LAB

Ans-C

Q-11: What is printed by the following statements?

s = "python rocks"
print(s[7:11] * 3)
A. rockrockrock
B. rock rock rock
C. rocksrocksrocks
D. Error, you cannot use repetition with slicing.

Ans-A

Q-12: What is the output of the following string operations

str = "My salary is 7000";


print(str.isalnum())

A. True
B. False

Ans-B

Join Telegram @SPPUBtech


Q-13: In Python, strings are…

A. str objects

B. Incorrect

C. changeable

D. Immutable

Ans-C

Q-14: What will be the output of the following Python statement?

>>>"a"+"bc"
a) a
b) bc
c) bca
d) abc

Answer: d
Explanation: + operator is concatenation operator.

Q-14: What will be the output of the following Python statement?

>>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc

Answer: c

Explanation: Slice operation is performed on string.

Q-15: The output of executing string.ascii_letters can also be achieved by:


a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) string.letters
d) string.lowercase_string.upercase

Answer: b
Explanation: Execute in shell and check.

Join Telegram @SPPUBtech


Q-16: What will be the output of the following Python code?

>>> str1 = 'hello'


>>> str2 = ','
>>> str3 = 'world'
>>> str1[-1:]

a) olleh
b) hello
c) h
d) o

Answer: d
Explanation: -1 corresponds to the last index.

Q-17: What arithmetic operators cannot be used with strings?


a) +
b) *
c) –
d) All of the mentioned

Answer: c
Explanation: + is used to concatenate and * is used to multiply strings.

Q-18: What will be the output of the following Python code?

>>>print (r"\nhello")

a) a new line and hello


b) \nhello
c) the letter r and then hello
d) error

Answer: b
Explanation: When prefixed with the letter ‘r’ or ‘R’ a string literal becomes a raw
string and the escape sequences such as \n are not converted.

Q-19: What will be the output of the following Python statement?

>>>print('new' 'line')
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line

Answer: c
Explanation: String literal separated by whitespace are allowed. They are
concatenated.

Join Telegram @SPPUBtech


Q-20: What will be the output of the following Python statement?

>>> print('x\97\x98')
a) Error
b)

97
98
c) x\97
d) \x97\x98

Answer: c
Explanation: \x is an escape sequence that means the following 2 digits are a
hexadecimal number encoding a character.

Q-21: What will be the output of the following Python code?

>>>str1="helloworld"
>>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld

Answer: a
Explanation: Execute in shell to verify.

Q-22: What will be the output of the following Python code?

print(0xA + 0xB + 0xC)


a) 0xA0xB0xC
b) Error
c) 0x22
d) 33

Answer: d
Explanation: 0xA and 0xB and 0xC are hexadecimal integer literals representing the
decimal values 10, 11 and 12 respectively. There sum is 33.

Join Telegram @SPPUBtech


Q-23: What will be the output of above Python code?

str1="6/4"

print("str1")

A. 1
B. 6/4
C. 1.5
D. str1
Ans : D
Explanation: Since in print statement, str1 is written inside double quotes so it
will simply print str1 directly.

Q-24: Which of the following will result in an error?

str1="python"

A. print(str1[2])
B. str1[1]="x"
C. print(str1[0:9])
D. Both (b) and (c)
Ans : B
Explanation: Strings are immutable. So,new values cannot be assigned at any
index position in a string

Q-25: Which of the following is False?

A. String is immutable.
B. capitalize() function in string is used to return a string by converting the whole
given string into uppercase.
C. lower() function in string is used to return a string by converting the whole given
string into lowercase.
D. None of these.
Ans : B
Explanation: capitalize() function in string gives the output by converting only the
first character of the string into uppercase and rest characters into
lowercase.However, upper() function is used to return the whole string into
uppercase.

Join Telegram @SPPUBtech


Q-26: What will be the output of below Python code?

str1="Information"

print(str1[2:8])

A. format
B. formatio
C. orma
D. ormat
Ans : A
Explanation: Concept of slicing is used in this question. In string slicing,the
output is the substring starting from the first given index position i.e 2 to one less
than the second given index position i.e.(8-1=7) of the given string str1. Hence,
the output will be "format".

Q-27: What will be the output of below Python code?

str1="Aplication"

str2=str1.replace('a','A')

print(str2)

A. application
B. Application
C. ApplicAtion
D. applicAtion
Ans : C
Explanation: replace() function in string is used here to replace all the existing "a"
by "A" in the given string.

Join Telegram @SPPUBtech


Q-28: What will be the output of below Python code?

str1="poWer"

str1.upper()

print(str1)

A. POWER
B. Power
C. power
D. poWer
Ans : D
Explanation: str1.upper() returns the uppercase of whole string str1. However,it
doesnot change the string str1. So, output will be the original str1.

Q-29:What will the below Python code will return?

If str1="save paper,save plants"

str1.find("save")

A. It returns the first index position of the first occurance of "save" in the given
string str1.
B. It returns the last index position of the last occurance of "save" in the given
string str1.
C. It returns the last index position of the first occurance of "save" in the given
string str1.
D. It returns the first index position of the first occurance of "save" in the given
string str1.
Ans : A
Explanation: It returns the first index position of the first occurance of "save" in
the given string str1.

Join Telegram @SPPUBtech


Q-30:What will the below Python code will return?

list1=[0,2,5,1]

str1="7"

for i in list1:

str1=str1+i

print(str1)

A. 70251
B. 7
C. 15
D. Error
Ans : D
Explanation: list1 contains integers as its elements. Hence these cannot be
concatenated to string str1 by simple "+" operand. These should be converted to
string first by use of str() function,then only these will get concatenated.

Q-31: Which of the following will give "Simon" as output?

If str1="John,Simon,Aryan"

A. print(str1[-7:-12])
B. print(str1[-11:-7])
C. print(str1[-11:-6])
D. print(str1[-7:-11])
Ans : C
Explanation: Slicing takes place at one index position less than the given second
index position of the string. So,second index position will be -7+1=-6.

Join Telegram @SPPUBtech


Q-32: What will following Python code return?

str1="Stack of books"

print(len(str1))

A. 13
B. 14
C. 15
D. 16
Ans : B
Explanation: len() returns the length of the given string str1, including spaces and
considering " " as a single character.

Q-33: What is the output when following code is executed ?

print r"\nhello"
The output is
A. a new line and hello
B. \nhello
C. the letter r and then hello
D. Error
Ans: B

Q-34: What is the output of “hello”+1+2+3 ?


A. hello123
B. hello
C. Error
D. hello6

Answer: Option C
Explanation:
Cannot concantenate str and int objects.

Join Telegram @SPPUBtech


Q-35:What is the output of the following?

print('ab'.isalpha())
A. True
B. False
C. None
D. Error

Answer: Option A
Explanation:
The string has only letters.

Q-36: What is the output of print str[0] if str = 'Hello World!'?

A - Hello World!

B-H

C - ello World!

D - None of the above.

Answer : B
Explanation
H is the correct answer.

Join Telegram @SPPUBtech


Q-37: What is the output of print tinylist * 2 if tinylist = [123, 'john']?

A - [123, 'john', 123, 'john']

B - [123, 'john'] * 2

C - Error

D - None of the above.

Answer : A
Explanation
It will print list two times. Output would be [123, 'john', 123, 'john'].

Q-38:Which of the following function convert a String to an object in python?

A - repr(x)

B - eval(str)

C - tuple(s)

D - list(s)

Answer : B
Explanation
eval(str) − Evaluates a string and returns an object.

Join Telegram @SPPUBtech


Q-39:Which of the following function convert a single character to its integer
value in python?

A - unichr(x)

B - ord(x)

C - hex(x)

D - oct(x)

Answer : B
Explanation
ord(x) − Converts a single character to its integer value.

Q-40 : Which of the following statement is used when a statement is required


syntactically but you do not want any command or code to execute?

A - break

B - continue

C - pass

D - None of the above.

Answer : C
Explanation
pass statement − The pass statement in Python is used when a statement is
required syntactically but you do not want any command or code to execute.

Join Telegram @SPPUBtech


Q-41 : Which of the following function checks in a string that all characters are in
uppercase?

A - isupper()

B - join(seq)

C - len(string)

D - ljust(width[, fillchar])

Answer : A
Explanation
isupper() − Returns true if string has at least 1 character and all characters are in
uppercase.

Q-42 : Which of the following function returns the min alphabetical character
from the string str?

A - lower()

B - lstrip()

C - max(str)

D - min(str)

Answer : D
Explanation
min(str) − Returns the min alphabetical character from the string str.

Join Telegram @SPPUBtech


Q-43 : What is the output of ['Hi!'] * 4?

A - ['Hi!', 'Hi!', 'Hi!', 'Hi!']

B - ['Hi!'] * 4

C - Error

D - None of the above.

Answer : A
Explanation
['Hi!', 'Hi!', 'Hi!', 'Hi!']

Q-44 : What is the following function removes last object from a list?

A - list.index(obj)

B - list.insert(index, obj)

C - list.pop(obj=list[-1])

D - list.remove(obj)

Answer : C
Explanation
list.pop(obj=list[-1]) − Removes and returns last object or obj from list.

Join Telegram @SPPUBtech


Combined Extra Multiple Choice Questions

1. Do we need to compiler a program before execution in Python?


A. Yes
B. No

Answer : B

2. How to output the string “May the odds favor you” in Python?

A. print(“May the odds favor you”)


B.echo(“May the odds favor you”)
C.System.out(“May the odds favor you”)
D.printf(“May the odds favor you”)

Answer : A

3. How to create a variable in Python with value 22.6?


A. int a = 22.6
B. a = 22.6
C. Integer a = 22.6
D. None of the above

Answer : B

4. How to add single-line comment in Python?


A. /* This is comment */
B. !! This is comment
C. // This is comment
D. # This is comment

Answer : D

5. How to represent 261500000 as a floating number in Python?


A. 2.615E8
B. 261500000
C. 261.5E8

Join Telegram @SPPUBtech


D. 2.6

Answer : A

6. Select the correct example of complex datatype in Python


A. 3 + 2j
B. -100j
C. 5j
D. All of the above are correct

Answer : D

7. What is the correct way of creating a multi-line string in Python?


A. str = “”My name is Kevin and I
live in New York””
B. str = “””My name is Kevin and I
live in New York”””
C. str = “My name is Kevin and I
live in New York”
D. All of the above

Answer : B

8. How to convert the uppercase letters in the string to lowercase in Python?


A. lowercase()
B. capilaize()
C. lower()
D. toLower()

Answer : C

9. How to access substring “Kevin” from the following string declaration in

Python:
1
2str = "My name is Kevin"
3
A. str[11:16]
B. str(11:16)

Join Telegram @SPPUBtech


C. str[11][16]
D. str[11-16]

Answer : A

10. Which of the following is the correct way to access a specific character. Let’s

say we need to access the character “K” from the following string in Python?
1
2str = "My name is Kevin"
3
A. str(11)
B. str[11]
C. str:9
D. None of the above

Answer : B

11. Which Python module is used to parse dates in almost any string format?
A. datetime module
B. time module
C. calendar module
D. dateutil module

Answer : D

12. Which of the following is the correct way to indicate Hexadecimal Notation in

Python?
A. str = ‘\62’
B. str = ’62’
C. str = “62”
D. str = ‘\x62’

Answer : D

13. To begin slicing from the end of the string, which of the following is used in

Python?
A. Indexing
B. Negative Indexing
C. Begin with 0th index

Join Telegram @SPPUBtech


D. Escape Characters
Answer : B

14. How to fetch characters from a given range in Python?


A. [:]
B. in operator
C. []
D. None of the above

Answer : A

15. How to capitalize only the first letter of a sentence in Python?


A. uppercase() method
B. capitalize() method
C. upper() method
D. None of the above

Answer : B

16. What is the correct way to get maximum value from Tuple in Python?
A. print (max(mytuple));
B. print (maximum(mytuple));
C. print (mytuple.max());
D. print (mytuple.maximum);

Answer : A

17. How to fetch and display only the keys of a Dictionary in Python?
A. print(mystock.keys())
B. print(mystock.key())
C. print(keys(mystock))
D. print(key(mystock))

Answer : A

18. How to align a string centrally in Python?


A. align() method
B. center() method
C. fill() method
D. None of the above

Join Telegram @SPPUBtech


Answer : B

19. How to access value for key “Price” in the following Python Dictionary:
1
2mystock = {
3"Product": "Earphone",
4"Price": 800,
5"Quantity": 50,
6"InStock" : "Yes"
7}
8
A. mystock[“Product”]
B. mystock(“Product”)
C. mystock[Product]
D. mystock(Product)

Answer : A

20. How to set the tab size to 6 in Python Strings?


A. expandtabs(6)
B. tabs(6)
C. expand(6)
D. None of the above

Answer : A

21. ___________ uses square brackets for comma-separated values in Python? Fill

in the blanks with a Python collection?


A. Lists
B. Dictionary
C. Tuples
D. None of the above

Answer : A

22. Are Python Tuples faster than Lists?


A. TRUE
B. FALSE

Answer : A

Join Telegram @SPPUBtech


23. How to find the index of the first occurrence of a specific value “i”, from string

“This is my website”?
A. str.find(“i”)
B. str.find(i)
C. str.index()
D. str.index(“i”)

Answer : D

24. How to display whether the date is AM/PM in Python?


A. Use the %H format code
B. Use the %p format code
C. Use the %y format code
D. Use the %I format code

Answer : B

25. Which of the following is the correcy way to access a specific element from a

Multi-Dimensional List?
A. list[row_size:column_size]
B. list[row_size][column_size]
C. list[(row_size)(column_size)]
D. None of the above

Answer : B

26. Which of the following Bitwise operators in Python shifts the left operand

value to the right, by the number of bits in the right operand. The rightmost bits

while shifting fall off?


A. Bitwise XOR Operator
B. Bitwise Right Shift Operator
C. Bitwise Left Shift Operator
D. None of the Above

Answer : B

Join Telegram @SPPUBtech


27. How to specify range of index in Python Tuples? Let’s say our tuple name is

“mytuple”
A. print(mytuple[1:4])
B. print(mytuple[1 to 4])
C. print(mytuple[1-4])
D. print(mytuple[].slice[1:4])

Answer : A

28. How to correctly create a function in Python?


A. demoFunction()
B. def demoFunction()
C. function demoFunction()
D. void demoFunction()

Answer : B

29. Which one of the following is a valid identifier declaration in Python?


A. str = “demo666”
B. str = “666”
C. str = “demo demo2”
D. str = “$$$666”

Answer : A

30. How to check whether all the characters in a string is printable?


A. print() method
B. printable() method
C. isprintable() method
D. echo() method

Answer : C

31. How to delete an element in a Dictionary with a specific key. Let’s say we need

to delete the key “Price”


A. del dict[‘Price’]
B. del.dict[‘Price’]
C. del dict(‘Price’)
D. del.dict[‘Price’]
Answer : A

Join Telegram @SPPUBtech


32. How to swap case in Python i.e. lowercase to uppercase and vice versa?
A. casefold() method
B. swapcase() method
C. case() method
D. title() method

Answer : B

33. The def keyword is used in Python to?


A. Define a function name
B. Define a list
C. Define an array
D. Define a Dictionary

Answer : A

34. Which of the following is used to empty the Dictionary in Python? Let’s say

our dictionary name is “mystock”.


A. mystock.del()
B. clear mystock
C. del mystock
D. mystock.clear()

Answer : D

35. How to display only the day number of year in Python?


A. date.strftime(“%j”)
B. date.strftime(“%H”)
C. date.strftime(“%I”)
D. date.strftime(“%p”)

Answer : A

36. What is used in Python functions, if you have no idea about the number of

arguments to be passed?
A. Keyword Arguments
B. Default Arguments
C. Required Arguments
D. Arbitrary Arguments
Answer : D

Join Telegram @SPPUBtech


37. What is the correct way to create a Dictionary in Python?
A. mystock = {“Product”: “Earphone”, “Price”: 800, “Quantity”: 50}
B. mystock = {“Product”- “Earphone”, “Price”-800, “Quantity”-50}
C. mystock = {Product[Earphone], Price[800], Quantity[50]}
D. None of the above

Answer : A

38. In Python Functions, what is to be used to skip arguments or even pass them in

any order while calling a function?


A. Keyword arguments
B. Default Arguments
C. Required Arguments
D. Arbitrary Arguments

Answer : A

39. How to get the total length of Tuple in Python?


A. count() method
B. length() method
C. len() method
D. None of the above

Answer : C

40. How to access a value in Tuple?


A. mytuple(1)
B. mytuple{1}
C. mytuple[1]
D. None of the above

Answer : C

41. What is to be used to create a Dictionary of arguments in a Python function?


A. Arbitrary arguments in Python (*args)
B. Arbitrary keyword arguments in Python (**args)
C. Keyword Arguments
D. Default Arguments

Answer : B

Join Telegram @SPPUBtech


42. How to convert the lowercase letters in the string to uppercase in Python?
A. upper()
B. uppercase()
C. capitalize()
D. toUpper()

Answer : A

43. What is the correct way to get minimum value from a List in Python?
A. print (minimum(mylist));
B. print (min(mylist));
C. print (mylist.min());
D. print (mylist.minimum());

Answer : B

44. Is using return statement optional in a Python Function?


A. Yes
B. No

Answer : A

45. Which of the following correctly converts int to float in Python?


A. res = float(10)
B. res = convertToFloat(10)
C. None of the above

Answer : A

46. How to get the type of a variable in Python?


A. print(typeOf(a))
B. print(typeof(a))
C. print(type(a))
D. None of the above

Answer : C

Join Telegram @SPPUBtech


47. How to compare two operands in Python and check for equality? Which

operator is to be used?
A. =
B. in operator
C. is operator
D. == (Answer)

Answer : D

48. What is the correct way to get minimum value from Tuple?
A. print (min(mytuple));
B. print (minimum(mytuple));
C. print (mytuple.min());
D. print (mytuple.minimum);

Answer : A

49. How to display only the current month’s number in Python?


A. date.strftime(“%H”)
B. date.strftime(“%I”)
C. date.strftime(“%p”)
D. date.strftime(“%m”)

Answer : D

50. How to compare two objects and check whether they have same memory

locations?
A. is operator
B. in operator
C. **
D. Bitwise operators

Answer : A

Join Telegram @SPPUBtech


51. How to fetch and display only the values of a Dictionary in Python?
A. print(mystock.value())
B. print(mystock.values())
C. print(values(mystock))
D. print(value(mystock))

Answer : A

52. Which operator is used in Python to raise numbers to the power?


A. Bitwise Operators
B. Exponentiation Operator (**)
C. Identity Operator (is)
D. Membership Operators (in)

Answer : B

53. Can we create a Tuple in Python without parenthesis?


A. TRUE
B. FALSE

Answer : A

54. ____________ represents key-value pair in Python?


A. Tuples
B. Lists
C. Dictionary
D. All the Above

Answer : C

55. Which of the following Bitwise operators sets each bit to 1, if only one of them

is 1, i.e. if only one of the two operands are 1.


A. Bitwise XOR
B. Bitwise OR
C. Bitwise AND
D. Bitwise NOT

Answer : A

Join Telegram @SPPUBtech


56. What is the correct way to get maximum value from a List in Python?
A. print (maximum(mylist));
B. print (mylist.max());
C. print (max(mylist));
D. print (mylist.maximum());

Answer : C

57. An example to correctly begin searching from the end range of index in

Python Tuples. Let’s say our Python Tuple has 4 elements


A. print(mytuple[-3 to -1])
B. print(mytuple[3-1])
C. print(mytuple[].slice[-3:-1])
D. print(mytuple[-3:-1])

Answer : D

58. Which of the following Bitwise operators in Python shifts the left operand

value to the left, by the number of bits in the right operand. The leftmost bits

while shifting fall off.


A. Bitwise XOR Operator
B. Bitwise Right Shift Operator
C. Bitwise Left Shift Operator
D. None of the Above

Answer : C

59. Can we update Tuples or any of its elements in Python after assignment?
A. Yes
B. No

Answer : A

Join Telegram @SPPUBtech


60. How to display only the current month’s name in Python?
A. date.strftime(“%H”)
B. date.strftime(“%B”)
C. date.strftime(“%m”)
D. date.strftime(“%d”)

Answer : B

61. ___________ uses Parenthesis for comma-separated values in Python? Fill in

the blanks with a Python collection?


A. List
B. Tuples
C. None of the above

Answer : B

62. How to create an empty Tuple in Python?


A. mytuple = ()
B. mytuple = (0)
C. mytuple = 0
D. mytuple =

Answer : A

63. Can we have duplicate keys in Python Dictionary?


A. TRUE
B. FALSE

Answer : B

64. Lists in Python are Immutable?


A. TRUE
B. FALSE

Answer : B

Join Telegram @SPPUBtech


65. What is the correct way to create a list with type float?
A. mylist = [5.7, 8.2, 9. 3.8, 2.9]
B. mylist = (5.7, 8.2, 9. 3.8, 2.9)
C. mylist = {5.7, 8.2, 9. 3.8, 2.9}
D. None of the above

Answer : A

66. How to display only the day number of year in Python?


A. date.strftime(“%j”)
B. date.strftime(“%H”)
C. date.strftime(“%I”)
D. date.strftime(“%p”)

Answer : A

67. Delete multiple elements in a range from a Python List


A. del mylist[2:4]
B. del mylist(2:4)
C. del mylist[2 to 4]
D. del mylist(2 to 4)

Answer : A

68. How to fetch last element from a Python List with negative indexing?
A. print(“Last element = “,mylist[0])
B. print(“Last element = “,mylist[])
C. print(“Last element = “,mylist[-1])
D. None of the above

Answer : C

69. What is the correct way to get the length of a List in Python?
A. mylist.count()
B. count(mylist)
C. len(mylist)
D. length(mylist)

Answer : C

Join Telegram @SPPUBtech


70. To get today’s date, which Python module is to be imported?
A. calendar module
B. datetime module
C. dateutil module
D. None of the above

Answer : B

Join Telegram @SPPUBtech

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy