Bird
0
0

What is wrong with this code?

medium📝 Debug Q14 of 15
Python - Modules and Code Organization
What is wrong with this code?
import random as r
print(random.randint(1, 5))
Arandom is not defined due to aliasing
Brandom module is not imported
Crandint function does not exist
DSyntax error in import statement
Step-by-Step Solution
Solution:
  1. Step 1: Analyze import aliasing effect

    The module random is imported as 'r', so the name 'random' is not defined in this code.
  2. Step 2: Identify cause of error

    Calling random.randint(...) causes a NameError because 'random' is undefined; should use 'r.randint(...)'.
  3. Final Answer:

    random is not defined due to aliasing -> Option A
  4. Quick Check:

    Aliased module name must be used [OK]
Quick Trick: Use alias name, not original module name [OK]
Common Mistakes:
  • Using original module name after aliasing
  • Assuming alias imports both names
  • Thinking randint is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes