qmb 3302 midterm
True or False: All operators produce an int output. - answer False. (They can produce a
float type)
Assuming this is a complete code chunk, and we expect to see output printed after
running this, why is the code below incorrect?
if tom_brady == the_goat:
print("The Bucs just won another Super Bowl!") - answer The variables are not defined
Suppose you wanted to drive down to Tampa to watch the Rays play baseball, but you
would only go if the cheapest ticket cost less than 20 dollars. If so, then your function
would output "Take me out to the ballgame!" Tickets cost 26 dollars. What function best
illustrates this? - answer None of these answers are correct. (missing colon after if
statement)
What type of error will you receive if you forget to indent your nested if statement? -
answerIndentationError
What is the output of the following code?
y = -0
if y >= 0:
print('0 or more')
else:
print('less than 0') - answer0 or more
Suppose you wanted to escape an otherwise infinitely repeating loop or function. How
would you do that? - answerStop the kernel
How many outputs will this following code have?
mosquito = 1
while mosquito > 0:
print(mosquito)
mosquito = mosquito + 1
print(mosquito) - answerThere are an infinite number of mosquitoes
Coach Napier is trying to count his total wins for the 2022 season. Which for loop
function will help him do so and produce the following output.
Coach Napier's Record at Florida
, 1 Loss
2 Win
3 Win
4 Win
5 Loss
Games played = 5
Wins to date = 3 - answerprint('Coach Napier's Record at Florida')
games_played = 0
games_won = ["Loss", "Win", "Win", "Win", "Loss"]
for N in games_won:
games_played = games_played + 1
print(games_played, N)
print("Games played = ", games_played)
print("Wins to date = ", games_won.count("Win"))
Identify the parts of a for loop.
For Iteration variable in [Select]:
[Select] - answerIterables; Statement
UF President Sasse wanted to define a function to count the student enrollment of the
top 3 colleges: Liberal Arts, Engineering, and Business. What 2 parts are missing in his
code?
MISSING college_count(liberal_arts, engineering, business):
enrollment = liberal_arts + engineering + business
MISSING enrollment
* Note that the function doesn't do anything yet, there are no values for the 3 variables. -
answerdef and return
What is the output from this code?
tom = "Doesn't like QMB3302"
if tom =!"loves to code":
tom = "will learn to love it"
if tom == "will learn to love it":
print("Coding will be fun")
if tom == "loves to code":
print("Tom will love this class") - answerCoding will be fun
What character do we use in Jupyter notebooks to create a comment? - answer#
In a print statement, what happens if you leave out one of the parentheses, or both (and
then run that cell in Jupyter)? - answerYou receive an error.
Syntax Error: missing parentheses
True or False: All operators produce an int output. - answer False. (They can produce a
float type)
Assuming this is a complete code chunk, and we expect to see output printed after
running this, why is the code below incorrect?
if tom_brady == the_goat:
print("The Bucs just won another Super Bowl!") - answer The variables are not defined
Suppose you wanted to drive down to Tampa to watch the Rays play baseball, but you
would only go if the cheapest ticket cost less than 20 dollars. If so, then your function
would output "Take me out to the ballgame!" Tickets cost 26 dollars. What function best
illustrates this? - answer None of these answers are correct. (missing colon after if
statement)
What type of error will you receive if you forget to indent your nested if statement? -
answerIndentationError
What is the output of the following code?
y = -0
if y >= 0:
print('0 or more')
else:
print('less than 0') - answer0 or more
Suppose you wanted to escape an otherwise infinitely repeating loop or function. How
would you do that? - answerStop the kernel
How many outputs will this following code have?
mosquito = 1
while mosquito > 0:
print(mosquito)
mosquito = mosquito + 1
print(mosquito) - answerThere are an infinite number of mosquitoes
Coach Napier is trying to count his total wins for the 2022 season. Which for loop
function will help him do so and produce the following output.
Coach Napier's Record at Florida
, 1 Loss
2 Win
3 Win
4 Win
5 Loss
Games played = 5
Wins to date = 3 - answerprint('Coach Napier's Record at Florida')
games_played = 0
games_won = ["Loss", "Win", "Win", "Win", "Loss"]
for N in games_won:
games_played = games_played + 1
print(games_played, N)
print("Games played = ", games_played)
print("Wins to date = ", games_won.count("Win"))
Identify the parts of a for loop.
For Iteration variable in [Select]:
[Select] - answerIterables; Statement
UF President Sasse wanted to define a function to count the student enrollment of the
top 3 colleges: Liberal Arts, Engineering, and Business. What 2 parts are missing in his
code?
MISSING college_count(liberal_arts, engineering, business):
enrollment = liberal_arts + engineering + business
MISSING enrollment
* Note that the function doesn't do anything yet, there are no values for the 3 variables. -
answerdef and return
What is the output from this code?
tom = "Doesn't like QMB3302"
if tom =!"loves to code":
tom = "will learn to love it"
if tom == "will learn to love it":
print("Coding will be fun")
if tom == "loves to code":
print("Tom will love this class") - answerCoding will be fun
What character do we use in Jupyter notebooks to create a comment? - answer#
In a print statement, what happens if you leave out one of the parentheses, or both (and
then run that cell in Jupyter)? - answerYou receive an error.
Syntax Error: missing parentheses