Bird
0
0

Find the error in this code:

medium📝 Debug Q14 of 15
Python - Modules and Code Organization
Find the error in this code:
import random
print(random.rand(5))
Arandom module is not imported
Brand is not a function in random module
Cprint statement syntax error
Drandom.rand(5) returns a list, not a number
Step-by-Step Solution
Solution:
  1. Step 1: Check module import

    The code correctly imports the random module, so no import error.
  2. Step 2: Verify function name in random module

    The random module does not have a function named rand. The correct function is randint or random.
  3. Final Answer:

    rand is not a function in random module -> Option B
  4. Quick Check:

    random.rand() does not exist [OK]
Quick Trick: Check function names carefully in modules [OK]
Common Mistakes:
  • Assuming all random functions start with 'rand'
  • Thinking import failed without error
  • Confusing function output types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes