Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (anonymous):

Ok, I just started with the lessons and I began the Rec 1. When he got to the demonstration portion I copied the script he has for finding the cube roots. # # Find the cube root of a perfect cube # x = int(raw_input("Enter an integer: ")) ans = 0 while ans*ans*ans < abs(x): ans = ans + 1 #print 'current guess =', 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) Syntax error at " != " why?

OpenStudy (anonymous):

Evidently I'm not capable of reading and copying simple information so I figured out where my error was.

OpenStudy (anonymous):

I read somewhere once, that it helps if, when you are copying code... once you've got it copied, read it backwards to compare and look for mistakes like this.

OpenStudy (anonymous):

Thank you. I'll have to try that next time instead of looking for soft objects to throw my computer at.

OpenStudy (anonymous):

Looks like you have a stray * on the line: if ans*ans*ans* != abs(x): The third * throws an error because there’s nothing to multiply against.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!