Name:     ID: 
 
Email: 

Python Programming Midterm

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

The if..elif..else executes only one block of code among several blocks.
a.
False
c.
True
b.
It depends on expression used.
d.
There is no elif statement in Python
 

 2. 

Comments are ignored by the Python interpreter. What symbol is needed at the beginning of the comment?
a.
@
c.
< >
b.
#
d.
[ ]
 

 3. 

What is used to concatenate two strings in Python?
a.
^ operator
c.
# operator
b.
, operator
d.
+ operator
 

 4. 

To obtain the length of a string, you can use which function?
a.
length( )
c.
length_input( )
b.
index( )
d.
len( )
 

 5. 

In the following code, num is a ____?

num = ‘5’
a.
boolean
c.
integer
b.
float
d.
string
 

 6. 

What keyword is used to define a function?
a.
while
c.
for
b.
def
d.
if
 

 7. 

Which data type represents a whole number?
a.
Boolean
c.
Integer
b.
String
d.
Float
 

 8. 

What will be printed with the following print statement?

print(‘2 + 2’)
a.
4
c.
2, 2
b.
2 2
d.
2 + 2
 

 9. 

What would be the following output:
print(4*2 , 4**2)
a.
24
c.
8  16
b.
16  8
d.
4*2  4**2
 

 10. 

Why would you use a while loop?
a.
to increase the range of code
c.
to repeat code
b.
to save time
d.
to repeat code until a condition is met
 

 11. 

Suppose a list with name test, contains 10 elements. You can get the 5th element from the test list using:
a.
test[‘4’]
c.
test[4]
b.
test[5]
d.
test[‘5’]
 

 12. 

What is used to define a body of a loop?
a.
parenthesis
c.
curly braces
b.
indentation
d.
quotation
 

 13. 

Which term is used to describe expressions that result in the value of either true or false?
a.
Selection
c.
Concatenation
b.
Conditional
d.
Boolean
 

 14. 

Which of these would be used to loop through instructions exactly 10 times?
a.
WHILE loop
c.
FOR loop
b.
If statement
 

 15. 

Which Python statement will check to see if a is greater than or equal to b?
a.
if (a > b)
c.
if a>b:
b.
if a >=b:
d.
if a is greater than b
 

 16. 

A syntax error in code means:
a.
there was no defined index
c.
you have not used enough characters
b.
Python cannot find the file to pass the code to
d.
there was an error with your typing and code structure
 

 17. 

Which of the following statements is true?
a.
the continue statement is used to skip the rest of the code inside the loop
c.
the break and continue statements are almost always used with the if, if...else, and if...elif...else statements.
b.
All of the above.
d.
the break statement terminates the loop containing it
 

 18. 

What is the output of the following code?

while 4 = = 4:
       print(‘4’)
a.
Syntax error
c.
4 is printed once
b.
4 is printed four times
d.
4 is printed infinitely until program closes
 

 19. 

What is used to take input from the user in Python?
a.
<>
c.
scan( )
b.
print( )
d.
input( )
 

 20. 

Which of the following is correct?
a.
A variable name can have symbols like: @, #, $ etc.
c.
A variable name can start with a underscore
b.
Reserved words can be used as a variable name
d.
A variable name can start with a digit
 



 
         Start Over