Bird
Raised Fist0

What does the random.randint(a, b) function do in Python?

easy🧠 Conceptual Q11 of Q15
Python - Standard Library Usage
What does the random.randint(a, b) function do in Python?
AReturns a random float between a and b
BReturns a random integer N such that a ≤ N ≤ b
CReturns a random element from a list
DShuffles the elements of a list in place
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function purpose

    random.randint(a, b) generates a random integer between two given numbers a and b, inclusive.
  2. Step 2: Compare options with function behavior

    Returns a random integer N such that a ≤ N ≤ b correctly describes this behavior. Options A, C, and D describe other functions like random.uniform, random.choice, and random.shuffle.
  3. Final Answer:

    Returns a random integer N such that a ≤ N ≤ b -> Option B
  4. Quick Check:

    random.randint = random integer in range [OK]
Quick Trick: randint returns integers between two numbers inclusive [OK]
Common Mistakes:
MISTAKES
  • Confusing randint with random float functions
  • Thinking randint returns a list element
  • Mixing up randint with shuffle

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes