Chapter 3 Quiz: Python for the Business Professional
Test your understanding of Python fundamentals, pandas basics, and the business case for coding. Select the best answer for each question.
Question 1
What is the primary advantage of Python over Excel for business data analysis?
A) Python is faster for all calculations B) Python can handle larger datasets, automate workflows, and integrate with AI/ML tools C) Python produces better-looking charts D) Python does not require any learning curve
Question 2
What does the following code output?
revenue = 500000
costs = 350000
margin = (revenue - costs) / revenue * 100
print(f"Margin: {margin}%")
A) Margin: 30%
B) Margin: 30.0%
C) Margin: 0.3%
D) An error, because you cannot multiply by 100
Question 3
Which of the following is a valid Python variable name?
A) 2nd_quarter
B) second-quarter
C) second_quarter
D) second quarter
Question 4
What error does this code produce?
store_name = "Downtown"
store_count = 47
message = store_name + " has " + store_count + " employees"
A) NameError
B) SyntaxError
C) TypeError
D) ValueError
Question 5
What does the following code print?
scores = [85, 92, 78, 95, 88]
print(scores[1])
A) 85
B) 92
C) 78
D) An error, because lists start at index 1
Question 6
What is the output of this code?
quarterly_revenue = 280000
target = 300000
if quarterly_revenue >= target:
status = "Met"
elif quarterly_revenue >= target * 0.9:
status = "Near"
else:
status = "Missed"
print(status)
A) Met
B) Near
C) Missed
D) An error
Question 7
What does pd refer to in the following code?
import pandas as pd
df = pd.read_csv("sales.csv")
A) A built-in Python module B) An alias (nickname) for the pandas library C) A variable that stores the CSV file path D) The name of the DataFrame
Question 8
Which pandas method shows the first 5 rows of a DataFrame?
A) df.first()
B) df.top(5)
C) df.head()
D) df.preview()
Question 9
What is the correct way to filter a pandas DataFrame for rows where revenue exceeds $50,000?
A) df.filter(revenue > 50000)
B) df[df["revenue"] > 50000]
C) df.where("revenue" > 50000)
D) df.select(revenue > 50000)
Question 10
What does the following code return?
sales_df.groupby("region")["revenue"].mean()
A) The total revenue for each region B) The average revenue for each region C) A filtered DataFrame showing only the "region" and "revenue" columns D) A single number — the overall average revenue
Question 11
Which of the following is NOT a valid pandas data type?
A) int64
B) float64
C) object (used for strings)
D) currency
Question 12
What is wrong with this code?
northeast = sales_df[sales_df["region"] == "Northeast" & sales_df["revenue"] > 50000]
A) Nothing — the code is correct
B) Each condition must be wrapped in parentheses when using &
C) You should use and instead of &
D) You cannot filter on two conditions at once in pandas
Question 13
What does df.shape return?
A) The number of rows B) The number of columns C) A tuple of (rows, columns) D) A description of the DataFrame's data types
Question 14
What does the following function return when called with calculate_discount(100, 0.15)?
def calculate_discount(price, rate=0.10):
return price * (1 - rate)
A) 90.0
B) 85.0
C) 15.0
D) 100.0
Question 15
You receive this error:
KeyError: 'revenues'
What is the most likely cause?
A) The pandas library is not installed
B) You misspelled a column name — the column is probably revenue, not revenues
C) The CSV file is corrupted
D) Your DataFrame is empty
Question 16
What is a Jupyter notebook cell?
A) A single unit of code or text within a notebook B) A type of spreadsheet cell C) A function that runs automatically D) A pandas data structure
Question 17
Which keyboard shortcut runs a cell and moves to the next one in Jupyter?
A) Ctrl+R
B) Shift+Enter
C) Alt+R
D) F5
Question 18
What does this list comprehension produce?
prices = [10, 25, 50, 75, 100]
result = [p * 1.08 for p in prices if p >= 50]
A) [10.8, 27.0, 54.0, 81.0, 108.0]
B) [54.0, 81.0, 108.0]
C) [50, 75, 100]
D) An error
Question 19
A colleague argues that learning Python is unnecessary because their company already uses Tableau for visualization. Which response best captures the argument from this chapter?
A) Python is always better than Tableau B) Python is free, while Tableau requires a license C) Python handles the full analytics pipeline — data loading, cleaning, analysis, modeling, and automation — while Tableau primarily handles visualization D) Tableau cannot connect to databases
Question 20
What is the output of this code?
store = {"name": "Downtown", "region": "NE", "revenue": 320000}
store["employees"] = 45
print(len(store))
A) 3
B) 4
C) 45
D) An error — you cannot add keys to a dictionary
Question 21
What does df.describe() show?
A) The first 5 rows of the DataFrame B) Column names and data types C) Summary statistics (count, mean, std, min, quartiles, max) for numeric columns D) The total memory usage of the DataFrame
Question 22
Which of the following best describes the relationship between Python and SQL for business analytics?
A) Python has replaced SQL entirely B) SQL is used for querying databases; Python is used for analysis, modeling, and automation — they are complementary C) SQL is better for all data tasks D) Python and SQL do exactly the same things
Question 23
You run the following code and get no output (an empty DataFrame):
result = sales_df[sales_df["revenue"] > 999999]
What is the most likely explanation?
A) The code has a syntax error
B) No rows in the dataset have revenue above 999,999
C) The revenue column does not exist
D) The DataFrame is corrupted
Question 24
What does the axis=1 parameter mean in pandas operations like df.apply(func, axis=1)?
A) Apply the function to each column B) Apply the function to each row C) Apply the function to the first row only D) Apply the function to both rows and columns
Question 25
Professor Okonkwo says: "You are not learning to be software engineers. You are learning to ask better questions." Which of the following best illustrates this principle?
A) Writing the most computationally efficient Python code possible B) Using Python to load, explore, filter, and summarize business data to answer specific business questions faster than manual methods allow C) Memorizing every pandas function D) Building a full web application in Python
Answer Key
-
B — Python's advantages are scale, automation, and integration with the broader AI/ML ecosystem, not raw speed for small calculations.
-
B — The calculation yields 30.0 (a float), and the f-string prints it with the decimal.
-
C — Variable names cannot start with a number (A), contain hyphens (B), or contain spaces (D).
-
C —
TypeError: Python cannot concatenate a string and an integer with+. You needstr(store_count)or an f-string. -
B — Python lists are zero-indexed.
scores[0]is 85,scores[1]is 92. -
B — 280,000 is below 300,000 (not "Met") but above 270,000 (which is 90% of 300,000), so the status is "Near."
-
B —
import pandas as pdloads the pandas library and assigns it the aliaspd. -
C —
df.head()displays the first 5 rows by default. You can pass a number to change this (e.g.,df.head(10)). -
B — Boolean indexing with
df[df["column"] > value]is the standard filtering syntax in pandas. -
B —
.mean()computes the average. Thegroupby("region")splits data by region first. -
D — There is no
currencydtype in pandas. Monetary values are stored asint64orfloat64. -
B — Without parentheses, Python evaluates
"Northeast" & sales_df["revenue"]first due to operator precedence. Correct:(sales_df["region"] == "Northeast") & (sales_df["revenue"] > 50000). -
C —
.shapereturns a tuple like(240, 6)representing (rows, columns). -
B — The second argument (0.15) overrides the default (0.10). Result:
100 * (1 - 0.15) = 85.0. -
B — A
KeyErrorin pandas almost always means you tried to access a column that does not exist, usually due to a typo. -
A — A cell is the basic unit of a Jupyter notebook, containing either code or markdown text.
-
B —
Shift+Enterruns the current cell and advances to the next one. -
B — The comprehension filters for prices >= 50 first (keeping 50, 75, 100), then multiplies each by 1.08.
-
C — Python covers the full analytics pipeline; Tableau is specialized for visualization. They serve different purposes and can complement each other.
-
B — The dictionary starts with 3 keys; adding
"employees"makes it 4. -
C —
describe()provides summary statistics for all numeric columns. -
B — SQL excels at querying and aggregating data in databases; Python excels at analysis, visualization, modeling, and automation. Most analysts use both.
-
B — An empty result from a filter means no rows matched the condition. The threshold is likely too high for this dataset.
-
B —
axis=1means "operate across columns for each row."axis=0(the default) means "operate down rows for each column." -
B — The chapter's core message is that Python is a tool for answering business questions, not an end in itself.