Name:     ID: 
 
Email: 

Python Programming Midterm

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

 1. 

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

 2. 

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

 3. 

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

 4. 

What will be printed with the following print statement?

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

 5. 

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.
the break statement terminates the loop containing it
d.
All of the above.
 

 6. 

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

 7. 

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

 8. 

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

 9. 

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

 10. 

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

 11. 

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

 12. 

In the following code, num is a ____?

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

 13. 

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

 14. 

What is the output of the following code?

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

 15. 

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

 16. 

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

 17. 

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

 18. 

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

 19. 

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
 

 20. 

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



 
         Start Over