Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q4 of Q15
Python - Standard Library Usage
What will be the output of this code?
import random
print(random.randint(1, 3))
AA random float between 1 and 3
BAlways 1
CA random integer: 1, 2, or 3
DAn error because randint needs floats
Step-by-Step Solution
Solution:
  1. Step 1: Understand randint behavior

    random.randint(1, 3) returns an integer between 1 and 3 inclusive.
  2. Step 2: Check output possibilities

    Output can be 1, 2, or 3 randomly; no error occurs.
  3. Final Answer:

    A random integer: 1, 2, or 3 -> Option C
  4. Quick Check:

    randint(1,3) = int 1 to 3 [OK]
Quick Trick: randint(a,b) includes both ends [OK]
Common Mistakes:
MISTAKES
  • Expecting float output
  • Thinking it always returns start
  • Believing it causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes