Name:     ID: 
 
Email: 

Python Programming Midterm

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

 1. 

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

 2. 

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.
 

 3. 

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

 4. 

What will be printed with the following print statement?

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

 5. 

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

 6. 

In the following code, num is a ____?

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

 7. 

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

 8. 

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

 9. 

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

 10. 

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

 11. 

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

 12. 

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

 13. 

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[5]
b.
test[‘5’]
d.
test[‘4’]
 

 14. 

What is the output of the following code?

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

 15. 

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

 16. 

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

 17. 

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

 18. 

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

 19. 

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

 20. 

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



 
         Start Over