Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

EthanC

  • 2 years ago

##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)

  • This Question is Open
  1. wio
    • 2 years ago
    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. wio
    • 2 years ago
    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.

  3. basking
    • 2 years ago
    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.

  4. harsimran_hs4
    • 2 years ago
    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)

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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.