Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JonathanFichter

I'm getting the rough sense that there's a difference between entering "import math" and "from math import *", but I'd love for someone to explain it to me more fully. The problem set told us to do the latter, but I had to also do the former in order to get square roots to work. To me, this was puzzling.

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. ewsmith
    Best Response
    You've already chosen the best response.
    Medals 0

    The statments do similar things but have different scoping. sqrt() is a method (function) in math. If you use "import math", to use the square root function you will need to call it with math.sqrt() If you use "from math import sqrt" you can call the function with just sqrt(). The "*" is a wildcard so with "from math import *" you are importing all of the methods in math. Both methods have there place. For smaller problems such as the homework assignment "from math import *" makes using sqrt() less typing. But if you are already using the name sqrt() to mean some other function than using "import math" avoids naming conflicts.

    • 2 years ago
  2. JonathanFichter
    Best Response
    You've already chosen the best response.
    Medals 0

    Great answer. Thanks!

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.