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

EthanC Group Title

##Can someone explains the different outcome if I ##change 0.1 to 0.5 at line " ans = ans + 0.1" ## while x = 8 ? x = float(raw_input('Enter a number:')) ans = 0.0 print type (ans) while ans*ans*ans < abs(x): ans = ans+0.1 ## ans = ans +0.5 print ans if ans*ans*ans != abs(x): print x , ' is not a perfect cube' else: if x<0: ans = -ans print 'Cube root of ', str(x), 'is' , str(ans)

  • 2 years ago
  • 2 years ago

  • This Question is Open
  1. wio Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I'm slightly confused. A perfect cube should had a cube root that is an integer, so why are you using a float here? If you change the line to ans = ans + 0.5, then you're going to be checking less cube roots. For example you wont check 0.1 or 0.2 or 0.3 or 0.4. Thus you have a greater probability of missing the cube root.

    • 2 years ago
  2. wio Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    There are better ways of finding the cube root, by the way. Like using Newton's root finding method.

    • 2 years ago
  3. basking Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Also, because you are checking fewer times (at a greater interval), that will impact the accuracy of your program's result.

    • 2 years ago
  4. harsimran_hs4 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    please use the pasting websites to paste your code http://pastebin.com/ http://dpaste.com/ definitely for the computation of a perfect cube you just need to increase the ans by 1 also you might be confused that you should not get 'not a perfect cube' , it is because of float point error.(the way computer perceives the number may be a little different than you may think)

    • 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.