0%

4- Numbers Quiz

A spell is only useful if you remember when to cast it. This quiz will test your understanding of Python numbers. No pressure. Just a quiet moment with yourself and a few questions.

You have learned about integers, floats, complex numbers, arithmetic operations, type conversion, and the hidden quirks of floating point precision. Now it is time to whisper the answers back to yourself. This quiz is not a test. Think of it as a mirror. It shows you what has settled into your memory and what needs another glance. Take your time. There is no score except the clarity you gain. Each question is followed by the correct answer and a short explanation. Try to answer before looking.

🕯️ Magic Note

The best programmers do not memorize everything. They remember where to look and trust their understanding of concepts. If you get a question wrong, it is not a failure. It is a map showing you exactly where to focus next. Every mistake is a whisper telling you “look here again.”

Question 1: The Three Types
What are the three numeric types in Python?
  • Option A: int, float, double
  • Option B: int, float, complex
  • Option C: integer, decimal, imaginary
  • Option D: number, decimal, complex
✨ Reveal Answer & Explanation
Correct Answer: B (int, float, complex) Python has three built-in numeric types. int for whole numbers (unlimited size). float for decimal numbers (based on IEEE 754, limited precision). complex for numbers with a real and imaginary part (written as a + bj). The other options are incorrect. “double” is not a separate type in Python (float is double precision). “decimal” requires importing the decimal module. And “imaginary” alone is not a type (it is part of complex).
Question 2: The Division Detective
What is the difference between / and // in Python?
  • Option A: / is for integers, // is for floats
  • Option B: / returns a float, // returns an integer after floor division
  • Option C: / rounds up, // rounds down
  • Option D: There is no difference, they are the same
✨ Reveal Answer & Explanation
Correct Answer: B (/ returns a float, // returns an integer after floor division) The / operator always performs true division and returns a float, even when the result is a whole number (10 / 2 becomes 5.0). The // operator performs floor division. It divides and rounds down to the nearest integer (toward negative infinity). For positive numbers, this works like truncation. For negative numbers, it can surprise you: -10 // 3 returns -4, not -3.
Question 3: The Precision Paradox
Why does 0.1 + 0.2 == 0.3 return False in Python?
  • Option A: Python has a bug in its addition operator
  • Option B: Floats cannot represent some decimal numbers exactly in binary
  • Option C: You must use decimal module for any decimal operation
  • Option D: 0.1 + 0.2 actually equals 0.30000000000000004 mathematically
✨ Reveal Answer & Explanation
Correct Answer: B (Floats cannot represent some decimal numbers exactly in binary) Computers store numbers in binary (base 2). Just as 1/3 cannot be represented exactly in decimal (0.33333…), certain decimal numbers like 0.1 and 0.2 cannot be represented exactly in binary. When you add them, the tiny rounding errors accumulate, resulting in 0.30000000000000004 instead of 0.3. This is not a Python bug. It is a limitation of how all modern computers handle floating point numbers (IEEE 754 standard). To compare floats safely, check if the absolute difference is very small: abs(a – b) < 1e-9.
Question 4: The Casting Spell
What does int(3.99) return?
  • Option A: 4 (rounded up)
  • Option B: 3 (truncated toward zero)
  • Option C: 3.99 (no change)
  • Option D: An error occurs
✨ Reveal Answer & Explanation
Correct Answer: B (3, truncated toward zero) The int() function truncates toward zero. It simply removes the decimal part without rounding. int(3.99) becomes 3, not 4. If you need rounding, use round(3.99) which returns 4.0. Or math.floor() for rounding down or math.ceil() for rounding up.
Question 5: The Floor Division Trap
What is the result of -7 // 3?
  • Option A: -2 (truncation toward zero)
  • Option B: -3
  • Option C: -4
  • Option D: Error: cannot use floor division with negatives
✨ Reveal Answer & Explanation
Correct Answer: B (-3) Floor division // always rounds down toward negative infinity, not toward zero. -7 divided by 3 is approximately -2.333… Rounding down toward negative infinity gives -3. But be careful with other negative combinations. -10 // 3 is -4 because -10 ÷ 3 = -3.333… which rounds down to -4. The rule is consistent: floor division always rounds toward negative infinity.
⚠️ The exact value of -7 // 3 is -3. However, be careful with different negative combinations. -10 // 3 is -4 because -10 ÷ 3 = -3.333… which rounds down to -4. The rule is consistent: floor division always rounds toward negative infinity. When in doubt, test in the Python interpreter or use int(a / b) for truncation toward zero.
Question 6: The Power Operator
What does 2 ** 5 calculate?
  • Option A: 2 × 5 = 10
  • Option B: 2 to the power of 5 = 32
  • Option C: 5 to the power of 2 = 25
  • Option D: 2 + 5 = 7
✨ Reveal Answer & Explanation
Correct Answer: B (2 to the power of 5 = 32) The ** operator is exponentiation (power). It raises the number on the left to the power of the number on the right. 2 ** 5 means 2 × 2 × 2 × 2 × 2 = 32. You can also use the pow() function: pow(2, 5) also returns 32.
Question 7: The Underscore Mystery
What is the value of 1_000_000 in Python?
  • Option A: A string containing “1_000_000”
  • Option B: An error (underscores are not allowed)
  • Option C: The number 1000000 (one million)
  • Option D: The number 1 (Python ignores everything after underscore)
✨ Reveal Answer & Explanation
Correct Answer: C (The number 1000000, one million) Python allows underscores in numeric literals to improve readability. The underscores are ignored completely. 1_000_000, 10_00_00, and 1000000 all represent the same number. You can use underscores anywhere in a number except at the beginning or end. This is especially useful for large numbers (like 1_000_000_000) or binary/hexadecimal numbers (0b1111_0000 or 0xFF_00_FF).
Question 8: The Limitless Integer
What happens when you compute 10 ** 1000 in Python?
  • Option A: Python crashes with an overflow error
  • Option B: It returns infinity (inf)
  • Option C: It returns a very large integer with 1001 digits
  • Option D: It returns a float approximation
✨ Reveal Answer & Explanation
Correct Answer: C (It returns a very large integer with 1001 digits) Python integers have unlimited precision. They can grow to any size limited only by your computer’s memory. 10 ** 1000 is a 1 followed by 1000 zeros (a thousand digits). Python handles this effortlessly. This is different from many other languages (like C, Java, or Go) where integers have fixed sizes and would overflow or crash. Floats, however, do have limits (about 1.8e308) and would return inf (infinity) for numbers this large.
Question 9: The Modulus Magic
What does 17 % 5 return?
  • Option A: 3 (the quotient)
  • Option B: 2 (the remainder)
  • Option C: 3.4 (the division result)
  • Option D: 1 (something else)
✨ Reveal Answer & Explanation
Correct Answer: B (2, the remainder) The % operator is the modulus or remainder operator. It returns the remainder after division. 17 divided by 5 equals 3 with a remainder of 2 (because 5 × 3 = 15, and 17 – 15 = 2). Modulus is extremely useful for checking even/odd numbers (number % 2 == 0), cycling through ranges, and many other patterns.
Question 10: The Type Detective
What is the output of print(type(42.0))?
  • Option A: <class ‘int’>
  • Option B: <class ‘float’>
  • Option C: <class ‘decimal’>
  • Option D: 42.0
✨ Reveal Answer & Explanation
Correct Answer: B (<class ‘float’>) The type() function returns the type of an object. Even though 42.0 has no fractional part, the presence of a decimal point makes it a float in Python. To create an integer, write 42 (without the decimal point). The decimal point is the signal to Python that you want a float.
Mini Challenges (Optional)
If you want to go deeper, try these small coding challenges. Write the code in a Python environment (or even just on paper) and predict the output before running it.

Challenge 1

a = 5

b = 2

print(a / b)

print(a // b)

print(a % b)

print(a ** b)

Challenge 2

print(int(7.9))

print(round(7.9))

print(int(-7.9))

print(-7 // 3)

Challenge 3

# Which of these are valid numbers in Python?

x = 1_234

y = 0xFF

z = 3 + 2j

w = 1.5e-3

✨ Reveal Challenge Answers
Challenge 1 Answers: – a / b = 2.5 (float division) – a // b = 2 (floor division) – a % b = 1 (remainder) – a ** b = 25 (power) Challenge 2 Answers: – int(7.9) = 7 (truncates toward zero) – round(7.9) = 8 (rounds to nearest integer) – int(-7.9) = -7 (truncates toward zero) – -7 // 3 = -3 (floor division rounds down toward negative infinity) Challenge 3 Answers: All of them are valid! 1_234 is an integer with underscore for readability. 0xFF is hexadecimal (255 in decimal). 3 + 2j is a complex number. 1.5e-3 is scientific notation (0.0015 as a float).
Self-Assessment
After completing this quiz, ask yourself:
  • Can you name the three numeric types without looking?
  • Do you understand when to use / vs //?
  • Do you know why floats sometimes behave strangely in comparisons?
  • Are you comfortable with type conversion (int(), float(), str())?
  • Do you remember the order of operations (PEMDAS)?
💡 If you answered “no” to any of these, do not worry. Go back to the Numbers lesson (Lesson 3) and re-read the sections where those concepts appear. Every master was once a beginner who asked the same questions twice. Or three times. Or more. That is how whispers become knowledge.

⚡ Whisper

You have looked into the mirror of numbers. Some answers came easily. Others required a pause, a second glance, maybe a whisper of doubt. This is not weakness. This is the shape of learning. Each question you answered wrong is now a seed planted in your mind. Water it with practice. Let it grow. The next time you face a float comparison or a floor division trap, you will remember this moment. And you will whisper back the correct answer. That is the conjure of repetition. That is how spells become instinct.

Related posts