CS 1064 - PYTHON MIDTERM EXAM QUESTIONS WITH
VERIFIED ANSWERS
The print statement is: - Answers - a call to a function
True/false: a python program must be compiled into an executable form before it can be
run - Answers - False
Define case sensitive - Answers - the difference between uppercase and lowercase
letters matter
What output does the following code produce? Print('apple', 'banana') - Answers -
apple banana
What output is produced by this? Print(15+30) - Answers - 45
What output is produced?
Print('Ready', end=' ')
Print('Set', end='')
Print('Go') - Answers - Ready setgo
What output is produced?
Print('oak', 'elm', 'pine', end='!', sep='#') - Answers - oak#elm#pine!
True/false: the value of a variable can change through a program - Answers - true
True/false: python variables are created using an assignment statement - Answers -
true
A python identifier can only be composed of: - Answers - letters (A-Z), digits (0-9), and
underscore character. Identifiers can't begin with a digit
By convention, variable names in python should be composed of: - Answers - all
lowercase letters, with words separated by underscore
All python variables are: - Answers - object references, meaning they are names that
refer to an object somewhere in memory
Assignment operators (=) have a _____ precedence than arithmetic operators -
Answers - lower
What are the arithmetic operators? - Answers - + = addition
, - = subtraction
* = multiplication
/ = division
% = gets remainder in integer division
** = exponent
// = integer/floor division, returning only integer quotient
True/false: in python, the assignment statement is also an expression - Answers -
false. The assignment operator doesn't return a value
True/false: you must use a print statement to display result of an expression in python
shell - Answers - false. The expression is evaluated and the result is displayed
immediately
Write code that produces the following line of output:
Don't you hate it when someone answers their own question? I do. - Answers -
print("Don't you hate it when someone answers their own question?", end=' ')
Print('I do.')
What are the modules in the python standard library that have to be imported first -
Answers - math
Random
String
Turtle
Datetime
Os
Urllib
Built-in functions vs. Built-in types (both don't have to be imported) - Answers - built-in
functions: print, input
Built-in types: int, float, str, list, range
True/false: the effect of the setheading depends on the current heading of the turtle -
Answers - false. When setting the heading explicitly, the current heading doesn't matter
Turtle heading (degrees) - Answers - see week of 8/30 doc
Turtle explicit positioning on coordinate system (goto function) - Answers - see week of
8/30 doc
Which way would turtle be facing after this code?
Turtle.setheading(270)
VERIFIED ANSWERS
The print statement is: - Answers - a call to a function
True/false: a python program must be compiled into an executable form before it can be
run - Answers - False
Define case sensitive - Answers - the difference between uppercase and lowercase
letters matter
What output does the following code produce? Print('apple', 'banana') - Answers -
apple banana
What output is produced by this? Print(15+30) - Answers - 45
What output is produced?
Print('Ready', end=' ')
Print('Set', end='')
Print('Go') - Answers - Ready setgo
What output is produced?
Print('oak', 'elm', 'pine', end='!', sep='#') - Answers - oak#elm#pine!
True/false: the value of a variable can change through a program - Answers - true
True/false: python variables are created using an assignment statement - Answers -
true
A python identifier can only be composed of: - Answers - letters (A-Z), digits (0-9), and
underscore character. Identifiers can't begin with a digit
By convention, variable names in python should be composed of: - Answers - all
lowercase letters, with words separated by underscore
All python variables are: - Answers - object references, meaning they are names that
refer to an object somewhere in memory
Assignment operators (=) have a _____ precedence than arithmetic operators -
Answers - lower
What are the arithmetic operators? - Answers - + = addition
, - = subtraction
* = multiplication
/ = division
% = gets remainder in integer division
** = exponent
// = integer/floor division, returning only integer quotient
True/false: in python, the assignment statement is also an expression - Answers -
false. The assignment operator doesn't return a value
True/false: you must use a print statement to display result of an expression in python
shell - Answers - false. The expression is evaluated and the result is displayed
immediately
Write code that produces the following line of output:
Don't you hate it when someone answers their own question? I do. - Answers -
print("Don't you hate it when someone answers their own question?", end=' ')
Print('I do.')
What are the modules in the python standard library that have to be imported first -
Answers - math
Random
String
Turtle
Datetime
Os
Urllib
Built-in functions vs. Built-in types (both don't have to be imported) - Answers - built-in
functions: print, input
Built-in types: int, float, str, list, range
True/false: the effect of the setheading depends on the current heading of the turtle -
Answers - false. When setting the heading explicitly, the current heading doesn't matter
Turtle heading (degrees) - Answers - see week of 8/30 doc
Turtle explicit positioning on coordinate system (goto function) - Answers - see week of
8/30 doc
Which way would turtle be facing after this code?
Turtle.setheading(270)