Bird
Raised Fist0

What will be the output of this code?

medium📝 Predict Output Q13 of Q15
Python - Standard Library Usage
What will be the output of this code?
import random
print(random.randint(1, 3))
ASyntaxError
BA random integer 1, 2, or 3
CA random float between 1 and 3
DAlways 1
Step-by-Step Solution
Solution:
  1. Step 1: Understand what random.randint does

    The function random.randint(1, 3) returns a random integer including both 1 and 3.
  2. Step 2: Predict the output range

    The output will be either 1, 2, or 3 randomly each time the code runs.
  3. Final Answer:

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

    random.randint(1,3) = 1, 2, or 3 [OK]
Quick Trick: randint(a,b) returns integer between a and b inclusive [OK]
Common Mistakes:
MISTAKES
  • Thinking randint returns a float
  • Expecting only 1 as output
  • Confusing randint with random.random()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes