QMB3302 Midterm 2
Greater than/equal to - answer>=
Less than - answer<
Not equal to - answer!=
Greater than - answer>
Equal to - answer==
less than or equal to - answer<=
Will the following nested "if" statement run? If not, why?
y = -0
if y > 0
if y > 5
print('higher')
if y <= 5
print('lower')
if y <=0
print('0 or less') - answernegative, ghost rider, there is a SyntaxError
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
A "while" loop is most closely related to which other type of function or statement.
(choose best answer) - answer"for" loop
Suppose you wanted to escape an otherwise infinitely repeating loop or function. How
would you do that? - answerStop the kernel
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 =
games_won = ["Loss", "Win", "Win", "Win", "Loss" ]
for N in games_won :
games_played = games_played +
print(games_played, N)
print("Games played = ", games_played)
print("Wins to date = ", games_won.count("Win"))
University of Florida President Kent Fuchs wanted to define a function to count the
student enrollment of the top three colleges: Liberal Arts, Engineering, and Business.
What two parts are MISSING in his code?
MISSING college_count(liberal_arts, engineering, business):
enrollment = liberal_arts + engineering + business
MISSING enrollment - answer"Def" and "return"
Imagine we have a dataframe, df. What would be the purpose for running code like the
below? (why would we run it?) - answerto look for, retrieve a value from df
imagine we have a pandas dataframe we have named 'df'
the dataframe consists of 2 columns
"col1" is 30 values long, and is a random mix of the letters 'a', 'b', and 'c'.
"num1" is also 30 values long, and is a random set of numerical data (all integers).
Which of the following would give you the mean of the numerical (num1) column,
grouped by the values from column "col1"? - answerdr.groupby('col1').mean()
What is the shape of the following numP array?
np.random.seed(1995)
x = np.random.randn(2, 2, 2, 2)
print(x.shape)
x - answer(2, 2, 2, 2)
what is the output of the following code?
import numpy as np
list1 = [5, 5, 5]
list2 = [10, 10, 10]
np_list1 = np.array(list1)
np_list2 = np.array(list2)
np_list1/np_list2 - answerarray([0.5, 0.5, 0.5)]
Greater than/equal to - answer>=
Less than - answer<
Not equal to - answer!=
Greater than - answer>
Equal to - answer==
less than or equal to - answer<=
Will the following nested "if" statement run? If not, why?
y = -0
if y > 0
if y > 5
print('higher')
if y <= 5
print('lower')
if y <=0
print('0 or less') - answernegative, ghost rider, there is a SyntaxError
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
A "while" loop is most closely related to which other type of function or statement.
(choose best answer) - answer"for" loop
Suppose you wanted to escape an otherwise infinitely repeating loop or function. How
would you do that? - answerStop the kernel
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 =
games_won = ["Loss", "Win", "Win", "Win", "Loss" ]
for N in games_won :
games_played = games_played +
print(games_played, N)
print("Games played = ", games_played)
print("Wins to date = ", games_won.count("Win"))
University of Florida President Kent Fuchs wanted to define a function to count the
student enrollment of the top three colleges: Liberal Arts, Engineering, and Business.
What two parts are MISSING in his code?
MISSING college_count(liberal_arts, engineering, business):
enrollment = liberal_arts + engineering + business
MISSING enrollment - answer"Def" and "return"
Imagine we have a dataframe, df. What would be the purpose for running code like the
below? (why would we run it?) - answerto look for, retrieve a value from df
imagine we have a pandas dataframe we have named 'df'
the dataframe consists of 2 columns
"col1" is 30 values long, and is a random mix of the letters 'a', 'b', and 'c'.
"num1" is also 30 values long, and is a random set of numerical data (all integers).
Which of the following would give you the mean of the numerical (num1) column,
grouped by the values from column "col1"? - answerdr.groupby('col1').mean()
What is the shape of the following numP array?
np.random.seed(1995)
x = np.random.randn(2, 2, 2, 2)
print(x.shape)
x - answer(2, 2, 2, 2)
what is the output of the following code?
import numpy as np
list1 = [5, 5, 5]
list2 = [10, 10, 10]
np_list1 = np.array(list1)
np_list2 = np.array(list2)
np_list1/np_list2 - answerarray([0.5, 0.5, 0.5)]