A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • one year ago

x= float(raw_input("enter a number: ")) ans =0 while ans*ans*ans < abs(x): ans=ans+.01 if ans*ans*ans!= abs(x): print x, ' is not a perfect cube' else: if x<0: ans=-ans print "the cube of "+str(x)+' is '+str(ans) ## can anyone please let me know what have i done wrong and how to fix it. I replaced 1 with .01 for the incremental. now even if i enter a number that has a perfect cube, the program cannot identify it. i still want to use .01 incremental value

  • This Question is Open
  1. rsst123
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    There you go! x = float(input("enter a number: ")) ans = 0 while (ans*ans*ans) < abs(x): ans= ans+.01 ans = round(ans, 1) if (ans*ans*ans) == x : print('the cube of ' + str(x) + ' is ' + str(ans)) else: print(str(x)+ ' is not a perfect cube')

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    val = float(raw_input("Enter a number: ")) ans = 0 while (ans**3) < abs(val): ans = ans + 0.01 print ans, 'is ans' # by adding this print statement you can see the value of ans each time the loop # executes. If you use the the value 9 as an input, you'll see that the last value of ans # is 2.09. But 2.09 * 2.0 9 * 2.09 = 9.129...... Since this value does not == 9. Then, # the program outputs that 9 is not a perfect square. if ans**3 != abs(val): print val, 'is not a perfect cube' else: if val < 0: ans = -ans print 'the cube of', val, 'is', ans # the solution to this problem is addressed by comparing the resulting 9.129... value # with the inputted value of 9 using an epsilon value. The comparison is: if 9.129 is # close enough to 9, then it (9) is a perfect square. This concept is covered in # lecture 3.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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


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