LearnFrenzy
Sign in Take a free test

Modules and Packages · Find the Error · Question 5

Error: a variable that replaces a module Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

The program below stops with an error. Which statement correctly describes the problem?

main.py
import math
math = 3.14                  # "the value of pi"
print(math.sqrt(4))
  • A It prints 2.0
  • B AttributeError: the name math now refers to a float, which has no sqrt; use another variable name Correct
  • C ImportError
  • D TypeError
Correct Answer: Option B

A module name is an ordinary variable and can be rebound by accident.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links