Quiz — Chapter 3: Python Basics
Instructions: Tests variables, data types, operators, and string operations. Answer key at end.
Multiple Choice
Q1. What is the data type of the value 0.0875 in Python?
a) int
b) float
c) str
d) bool
Q2. What does 100 // 3 evaluate to?
a) 33.333...
b) 33
c) 1
d) 34
Q3. What does 100 % 3 evaluate to?
a) 33
b) 33.333...
c) 1
d) 0
Q4. Which variable name is invalid in Python?
a) monthly_revenue
b) q3_sales
c) _temp_value
d) 3rd_quarter
Q5. What is the output of print("5" + "3")?
a) 8
b) 53
c) "53"
d) TypeError
Q6. Which format specifier displays 0.342 as 34.2%?
a) :.2f
b) :.1%
c) :.342%
d) :2%
Q7. What is the value of True and False?
a) True
b) False
c) None
d) 0
Q8. What does int(29.99) return?
a) 30
b) 29.99
c) 29
d) ValueError
Q9. Which of the following correctly computes compound growth?
a) principal * 1 + rate ** years
b) principal * (1 + rate) ** years
c) principal * (1 + rate * years)
d) (principal + rate) ** years
Q10. What is None in Python?
a) The integer 0
b) An empty string
c) The boolean False
d) The absence of a value — a null/empty placeholder
True or False
Q11. "Revenue" == "revenue" evaluates to True in Python.
Q12. balance += 500 is shorthand for balance = balance + 500.
Q13. 0.1 + 0.2 == 0.3 evaluates to True in Python.
Q14. Python variable names are case-sensitive — Revenue and revenue are different variables.
Q15. The // operator always returns an integer.
Q16. not True evaluates to False.
Q17. None == False evaluates to True.
Q18. The ** operator in Python performs exponentiation (power).
Q19. f-strings require you to call str() on numeric variables before embedding them.
Q20. 5 * "ha" in Python produces a TypeError.
Short Answer
Q21. Write a single line of Python that converts the string "$45,000" into a float. (Hint: you'll need a string method first.)
Q22. Write an f-string that displays the variable margin = 0.3875 as "Gross margin: 38.8%".
Q23. Explain in one sentence why float arithmetic can produce unexpected results (like 0.1 + 0.2 = 0.30000000000000004).
Q24. What is the output of "acme corp".title()?
Applied
Q25. Given the following:
revenue = 250_000
cogs = 162_500
expenses = 48_000
tax_rate = 0.21
Write the Python expressions (not a full script) that compute: a) Gross profit b) Gross margin rate (as a percentage with 1 decimal) c) Operating profit (gross profit minus expenses) d) Net profit (operating profit minus taxes on operating profit)
Answer Key
Multiple Choice: Q1: b | Q2: b | Q3: c | Q4: d | Q5: b | Q6: b | Q7: b | Q8: c | Q9: b | Q10: d
True or False:
Q11: False (case-sensitive)
Q12: True
Q13: False (floating-point imprecision; result is 0.30000000000000004)
Q14: True
Q15: True (// always returns an integer when both operands are integers; float when either is float)
Q16: True
Q17: False (None is not equal to False; None == False → False)
Q18: True
Q19: False (f-strings automatically convert embedded values to strings)
Q20: False (5 * "ha" → "hahahahaha" — valid repetition operator)
Short Answer:
Q21: float("$45,000".replace("$", "").replace(",", "")) → 45000.0
Q22: f"Gross margin: {margin:.1%}"
Q23: Computers store floating-point numbers in binary format, which cannot represent most decimal fractions exactly — so 0.1 and 0.2 are stored as the closest binary approximation, and their sum introduces a tiny rounding error.
Q24: "Acme Corp" (title-cases each word)
Applied (Q25):
gross_profit = revenue - cogs # 87,500
gross_margin = (revenue - cogs) / revenue # 0.35 → display: 35.0%
operating_profit = gross_profit - expenses # 39,500
net_profit = operating_profit * (1 - tax_rate) # 31,205