CH 2: Python Operators and
Control Flow Statements [22616
MAD]
Total points 20/20
Stay Tuned for Daily MCQs for All 6th Semester subs Computer EGG Group
Online Quiz to help you in preparing for Online Exams, It covers Multiple Choice
Questions (MCQs) for 20 Marks
imp Links:
All Theory tutorials: https://bit.ly/335XFKi
contact us on [email protected]
1. Which is the correct operator for power(xy)? * 1/1
a) x^y
b) x**y
c) x^^y
d) None of the mentioned
2. Which one of these is floor division? * 1/1
a) /
b) //
c) %
d) None of the mentioned
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 1/8
3. What is the order of precedence in python? * 1/1
a) i,ii,iii,iv,v,vi
b) ii,i,iii,iv,v,vi
c) ii,i,iv,iii,v,vi
d) i,ii,iii,iv,vi,v
4. What is the answer to this expression, 22 % 3 is? * 1/1
a) 7
b) 1
c) 0
d) 5
5. Mathematical operations can be performed on a string. * 1/1
True
False
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 2/8
6. What is the output of this expression, 3*1**3? * 1/1
a) 27
b) 9
c) 3
d) 1
7. Which one of the following has the same precedence level? 1/1
*
a) Addition and Subtraction
b) Multiplication, Division and Addition
c) Multiplication, Division, Addition and Subtraction
d) Addition and Multiplication
8. The expression Int(x) implies that the variable x is converted 1/1
to an integer. *
True
False
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 3/8
9. What is the output of print(2%6) * 1/1
ValueError
0.33
10. Which of these is the keyword? * 1/1
A. in
B. is
C. assert
D. All of the above
11. What is the output of print(5 is 5) * 1/1
True
False
Error
12. What is the output of print(1 in L1) L1=[1,2,3] * 1/1
True
False
NameError
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 4/8
13. The range() function by default returns a ____ * 1/1
tuple
string
dict
list
14. Select Conditional Statements that are available in python * 1/1
if
else if
elif
if elif
if else
15. What is the output of list(range(10)) * 1/1
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[ 1, 2, 3, 4, 5, 6, 7, 8, 9,10]
[(1, 2, 3, 4, 5, 6, 7, 8, 9,10)
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 5/8
16. Is for loop possible without range() in Python * 1/1
Yes
No
Maybe
17. Python provides keywords to perform logical operation, 2/2
Select correct keywords from following *
assert
continue
import
break
await
pass
else
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 6/8
18 Which code is correct for this output? * 2/2
Option 1
Option 2
Both above Options
None of the above
Feedback
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 7/8
Happy Learning! cwipedia.in
This content is neither created nor endorsed by Google. - Terms of Service - Privacy Policy
Forms
https://docs.google.com/forms/d/e/1FAIpQLSd9DOXNK1pTiLbDr6kILkPdDEhEze2Bl7BxCXeqWTHTcbxKsg/viewscore?viewscore=A… 8/8
EECS
183
Fall
2014
Exam
2
Closed
Book
Minimal
Notes
Closed
Electronic
Devices
Closed
Neighbor
Turn
off
Your
Cell
Phones
We
will
confiscate
all
electronic
devices
that
we
see
–
including
cell
phones,
calculators,
etc.
Multiple
Choice
Questions
(20
questions
*
6
points
per
question
=
120
points)
Key
1
Instructions:
Read
Carefully!
1.
You
may
have
one
3"
x
5"
handwritten
notecard.
2.
Some
questions
are
not
simple.
Therefore,
read
carefully.
3.
Assume
all
code
and
code
fragments
are
syntactically
valid,
unless
otherwise
specified.
4.
Assume/use
only
the
standard
C++11
/
Python
2.7.
5.
In
all
the
given
code,
if
any
character
looks
like
a
space,
it
is
one.
6.
On
the
scantron
sheet,
bubble
in
your
name
and
UMID
-‐-‐
10
pts
off
for
incorrect
UMID.
7.
On
the
scantron
sheet,
bubble
in
Key
1
-‐-‐
zero
on
exam
if
key
not
bubbled
in.
8.
Sign
below
and
print
your
uniqname
-‐-‐
10
pts
off
if
we
cannot
read
your
uniqname
“I
have
neither
given
nor
received
aid
on
this
examination,
nor
have
I
concealed
any
violations
of
the
Honor
Code.”
_________________________________________________________________________________________________________
Signature uniqname
1 of 12
This
page
intentionally
left
blank
for
your
us
2 of 12
C++
1. Which is an invalid function declaration, given the following code?
const int WIDTH = 5;
const int HEIGHT = 3;
A. void foo(int arr[HEIGHT][WIDTH]);
B. void foo(int arr[][WIDTH]);
C. void foo(int arr[][]);
D. void foo(int arr[5][3]);
E. void foo(int arr[][3]);
2. Suppose we have the following code:
int arr[5][3] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12},{13,14,15}};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cout << arr[i][j] << ' ';
}
cout << endl;
}
What will print as a result of running the above code?
A. 1 2 3 D. 1 2 3 4 5
4 5 6 6 7 8 9 10
7 8 9 11 12 13 14 15
B. 1 4 7 E. 1 4 7 10 13
2 5 8 2 5 8 11 14
3 6 9 4 6 9 12 15
C. 1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
3 of 12
C++
3. Given the following code:
const int SIZE = 5;
char a[SIZE][SIZE];
for (int i = 0; i < SIZE; i++) {
a[i][i+1] = i;
}
What is the first location accessed by this code that goes out of bounds of the array?
A. a[-1][0]
B. a[0][-1]
C. a[4][5]
D. a[5][6]
E. The code never goes out of bounds of the array.
4. The swap function below contains a bug. If a and b are declared integers in main,
which assigned values would activate the bug in the code when swap(a,b) is
called?
void swap (int &x, int &y) {
int temp = (x / y) * y + (x % y);
x = (y / x) * x + (y % x);
y = temp;
}
A. a = 1; b = 1;
B. a = 0; b = 1;
C. a = 1; b = 2;
D. a = 2; b = 1;
E. a = 1; b = -1;
4 of 12
C++
For questions 4 and 5, consider the following code.
Steve has written a new cipher function in C++, which he calls “sillyCipher”. It is
implemented in the following function:
void sillyCipher(const string &original, string &result) {
for (int x = 0; x < original.length(); x++) {
if (original[x] >= 'A' && original[x] <= 'M') {
result[x] = 'A';
}
else if (original[x] >= 'N' && original[x] <= 'Z') {
result[x] = 'B';
}
}
}
5. Suppose sillyCipher is called and a string containing "LISA" is passed as the
first parameter. What would be stored in result by the end of sillyCipher’s
execution (assuming result is also of length 4)?
A. "AABA"
B. "ABAA"
C. "ABAB"
D. "BBAB"
E. "BABA"
6. Which of the following sentences best describes the behavior of sillyCipher?
A. It is a clever and useful cipher, since it was written by Steve.
B. It is not a useful cipher because its result cannot be decoded.
C. It will not compile because one cannot index into strings like arrays.
D. It will not work correctly because it has an off-by-one error.
E. It will not work correctly because one of the strings is designated const.
5 of 12
C++
I/O
7. Which of the following is not a valid stream state?
A. good
B. bad
C. fail
D. eof
E. clear
8. Which line of the following code contains a bug?
1 #include <iostream>
2 #include <fstream>
3 #include <string>
4 using namespace std;
5
6 int main() {
7 ifstream inFile;
8 ifstream.open("myFile.txt");
9 if (!inFile) {
10 cout << "Could not open file." << endl;
11 return 1;
12 }
13 string line;
14 getline(inFile, line);
15 cout << line << endl;
16 inFile.close();
17 return 0;
18 }
A. line 7
B. line 8
C. line 9
D. line 14
E. line 15
6 of 12
C++
Classes
The following code will be used for Questions 9, 10, and 11.
Given the following definition of a class named Square.
class Square {
public:
void setLength(int newLength) {
length = newLength;
areaValue = length * length;
}
int area() const {
return areaValue;
}
private:
int length;
int areaValue;
};
9. The area member function is an example of a:
A. constructor
B. destructor
C. getter
D. setter
E. void function
10. What does const after int area() mean?
A. area() returns a constant value.
B. area() does not modify the value of areaValue.
C. area() does not modify any member variables’ values.
D. The programmer cannot modify the implementation of area().
E. No other functions named area() can exist.
7 of 12
C++
11. Which of the following implementations of a constructor for Square would be
correct and consistent with other member functions if implemented within the
class along with setLength and area?
A. Square() {
length = 1;
}
B. Square() {
length = 1;
area = 1;
}
C. Square() {
setLength(1);
}
D. void Square() {
length = 1;
}
E. void Square() {
length = 1;
areaValue = 1;
}
12. In C++ classes, by default, member variables are _________ and member
functions are _____________
A. public, public
B. public, private
C. private, public
D. private, private
E. C++ class members have undefined default behavior.
8 of 12
Python
Python
13. Python is a(n):
A. C++ library
B. compiler
C. integrated developer environment (IDE)
D. programming language
E. web browser
14. An array in C++ is best compared to which data structure in Python?
A. class
B. dictionary
C. float
D. list
E. range
15. What does the following code print?
fibonacci = [1, 1, 2, 3, 5, 8, 13, 21]
print fibonacci[1:3]
A. [1, 1, 2, 3]
B. [1, 2, 3]
C. [1, 2]
D. [1, 1, 2]
E. [1, 2, 3, 5, 8, 13, 21]
9 of 12
Python
16. What prints after the execution of the following Python code if the user inputs
0<ENTER>?
x = int(raw_input())
if x == 0:
print 'x is 0'
elif x == 1:
print 'x is 1'
print 'x is an integer'
A. x is 0
B. x is 0
x is an integer
C. x is 1
x is an integer
D. x is an integer
E. Nothing prints.
17. What does the following code print?
lst = []
nums = [15, 6]
lst.append(nums)
nums = [10, 30, 20]
lst.append(nums)
lst.sort()
print lst
A. [6, 10, 15, 20, 30]
B. [[6, 15], [10, 20, 30]]
C. [[15, 6], [10, 30, 20]]
D. [[10, 30, 20], [15, 6]]
E. [[10, 20, 30], [6, 15]]
10 of 12
Python
18. What does the following print?
import sys
def foo(n):
for i in range(0, n):
print " " * i,
print "*" * (n - i)
def main(argv):
foo(3)
if __name__ == '__main__':
main(sys.argv)
A. *
** D. ******
***
B. *** E. ***
**
* **
C. *** *
**
*
19. Which of the following is NOT a valid operation on a string variable in Python?
A. Addition of strings, which is equivalent to appending strings:
print 'Hello ' + ' World!'
B. Addition of strings and integers, which is equivalent to appending integers to
strings:
course = 'EECS ' + 183
C. Multiplication of string and integers, which repeats the string the integer number
of times:
'$' * 5
D. Indexing into a string to get a single letter of the string:
name = 'Maxim'
c = name[0]
E. Assignment of an integer to a variable currently holding a string:
course = 'EECS 183'
course = 183
11 of 12
Python
20. What does the following code output?
s = 'ABC'
n = 1
for c in s:
print c * n,
n += 1
A. A
B
C
B. A B C
C. A
BB
CCC
D. A BB CCC
E. 1 4 9
12 of 12
Unit 3: Data Structures in Python
Total points 30/30
Stay Tuned for Daily MCQs for All 6th Semester subs Computer EGG Group
Online Quiz to help you in preparing for Online Exams, It covers Multiple Choice
Questions (MCQs) for 30 Marks
imp Links:
All Theory tutorials: https://bit.ly/335XFKi
contact us on [email protected]
1. Lists are * 1/1
A. Immutable
B. Mutable
C. Both A & B
D. None of the above
2. How to define an empty list * 1/1
A. list[]
B. listname=[ ]
C. listname[]
D. list=()
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 1/10
3. What is the output of list1=[1,2,3] print(list1[1]) * 1/1
A. 2
B. 1
C. 3
D. 0
4. Which python function is used to return length? * 1/1
A. len()
B. length()
C. obj.len
D. none of the mention
5. Does python allow negative indexing? * 1/1
Yes
No
Maybe
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 2/10
6. The Slice operation is performed on a list using * 1/1
A. slice
B. : (colon)
C. .(dot)
D. - (hyphen)
7. What is the output of * 1/1
A. [1, 2, 3, 4, 6]
B. Error
C. None
D. [6,1,2,3,4]
8. What is the output of * 1/1
A. [1, 2, 3, 4, 6]
B. [6, 1, 2, 3, 4]
C. [1, 6, 2, 3, 4]
D. [1, 2, 6, 3, 4]
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 3/10
9. What is the output of * 1/1
A. [1, 2, 3, 4, 5, 6, 7, 8]
B. [1, 2, 6, 3, 4]
C. [5, 6, 7, 8, 1, 2, 3, 4]
D. error
10. What is the output of * 1/1
A. 4
B. [1, 2, 3, 4]
C. 5
D. error
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 4/10
11. We can delete element from the list by using, Select correct 1/1
answers *
A. 'del'
B. remove()
C. pop()
D. clear()
E. All the above
12. What will be the output * 1/1
A. 6
B. error
C. 7
D. [6, 7, 8]
13. The python tuple is _____ in nature. * 1/1
A. Unchangeable
B. Immutable
C. Both A & B
D. Mutable
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 5/10
14. What is the output of * 1/1
A. ('p', 'e', 'd', 'i', 'a')
B. ('i', 'p', 'e', 'd', 'i', 'a')
C. Slicing tuple is not possible
D. error
15. Select the build-in functions of tuple * 1/1
A. count()
B. index()
C. pop()
D. __add__()
E. clear()
16. Does the python set have duplicate elements? * 1/1
Yes
No
Maybe
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 6/10
17. Does the set supports indexing * 1/1
Yes
No
Maybe
18. Is slicing allowed in Set * 1/1
A. allowed
B. not allowed
19. What is the output of * 1/1
A. {1, 2, 3, 4, 5, 6, 7, 8}
B. {1, 2, 3, 4, 5, 4, 5, 6, 7, 8}
C. {1, 2, 3, 4, 4, 5, 6, 7, 8}
D. error
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 7/10
20. Python dictionaries are ______ * 1/1
A. Mutable
B. Immutable
21. What is the output of * 2/2
{'brand': 'Ford', 'model': 'Mustang', 'year': 2018}
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
ERROR
22. What is the output of * 2/2
Yes, 'model' is one of the keys in the thisdict dictionary
No output
Error
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 8/10
23. What is the output of * 2/2
error
24. What is the output of * 2/2
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964, 'color': 'red'}
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964, 'color': '}
error
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscore… 9/10
25. What is the output of * 2/2
name 'thisdict' is not defined
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964, 'color': 'red'}
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
Feedback *
cwipedia.in
This content is neither created nor endorsed by Google. - Terms of Service - Privacy Policy
Forms
https://docs.google.com/forms/d/e/1FAIpQLScV3TIKs3YPXeDIMyLsXmBUia4T8AmwGKubdvWtrblNVP4FXw/viewscore?viewscor… 10/10
Introduction & syntax of Python
Program [ MSBTE 22616 Python ]
Total points 20/20
Stay Tuned for Daily Quizzes on All 6th Semester Computer Group Subjects like
PHP, Python, MAD, and other
Online Quiz to help you in preparing for Online Exams, It covers Multiple Choice
Questions (MCQs) for 20 Marks
imp Links:
All Theory tutorials: https://bit.ly/335XFKi
contact us on [email protected]
Email (Optional)
1. Python was developed by * 1/1
A. Guido van Rossum
B. James Gosling
C. Dennis Ritchie
D. Bjarne Stroustrup
https://docs.google.com/forms/d/e/1FAIpQLSfjDdVe3JeBd9NC3fPsjxCd8KL996QLUeW7TuuGx5_K31yNgg/viewscore?viewscore=A… 1/7
2. Python was developed in which year? * 1/1
A. 1972
B. 1995
C. 1989
D. 1981
3. Python is written in which language? * 1/1
A. C
B. C++
C. Java
D. None of the above
4. What is the extension of the python file? * 1/1
A. .p
B. .py
C. .python
D. None of the above
https://docs.google.com/forms/d/e/1FAIpQLSfjDdVe3JeBd9NC3fPsjxCd8KL996QLUeW7TuuGx5_K31yNgg/viewscore?viewscore=A… 2/7
5. Python is an Object-Oriented Programming Language. * 1/1
True
False
6. Python 3.0 is released in which year? * 1/1
A. 2000
B. 2008
C. 2011
D. 2016
7. Which of the following statements is true? * 1/1
A. Python is a high level programming language.
B. Python is an interpreted language.
C. Python is an object-oriented language
D. All of the above
8. What is used to define a block of code in Python? * 1/1
A. Parenthesis
B. Indentation
C. Curly braces
D. None of the above
https://docs.google.com/forms/d/e/1FAIpQLSfjDdVe3JeBd9NC3fPsjxCd8KL996QLUeW7TuuGx5_K31yNgg/viewscore?viewscore=A… 3/7
9. By the use of which character, single line is made comment 1/1
in Python? *
A. *
B. @
C. #
D. !
10. What is a python file with .py extension called? * 1/1
A. package
B. module
C. directory
D. None of the above
11. Is python programming uses a pair of curly braces {} * 1/1
True
False
https://docs.google.com/forms/d/e/1FAIpQLSfjDdVe3JeBd9NC3fPsjxCd8KL996QLUeW7TuuGx5_K31yNgg/viewscore?viewscore=A… 4/7
12. Which statement is correct? * 2/2
A. List is immutable && Tuple is mutable
B. List is mutable && Tuple is immutable
C. Both are Mutable.
D. Both are Immutable
13. What is the output of the following program: print((1, 2) + (3, 2/2
4)) *
A. (1, 2), (3, 4)
B. (4, 6)
C. (1, 2, 3, 4)
D. Invalid Syntax
14. Which one of the following is a mutable data type? * 1/1
A. set
B. int
C. str
D. tupl
https://docs.google.com/forms/d/e/1FAIpQLSfjDdVe3JeBd9NC3fPsjxCd8KL996QLUeW7TuuGx5_K31yNgg/viewscore?viewscore=A… 5/7
15. Which one of the following is an immutable data type? * 1/1
A. list
B. set
C. int
D. dict
16. Which of these is not a core data type? * 1/1
(A) Lists
(B) Dictionary
(C) Tuples
(D) Class
17. What data type is the object below? L = [1, 23, 'hello', 1] * 1/1
a) list
b) dictionary
c) array
d) tuple
https://docs.google.com/forms/d/e/1FAIpQLSfjDdVe3JeBd9NC3fPsjxCd8KL996QLUeW7TuuGx5_K31yNgg/viewscore?viewscore=A… 6/7
18. Which function is used to take input in python? * 1/1
A. scanf()
B. int()
C. promt()
D. input()
Happy Learning!
cwipedia.in
This content is neither created nor endorsed by Google. - Terms of Service - Privacy Policy
Forms
https://docs.google.com/forms/d/e/1FAIpQLSfjDdVe3JeBd9NC3fPsjxCd8KL996QLUeW7TuuGx5_K31yNgg/viewscore?viewscore=A… 7/7