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?
Evidently I'm not capable of reading and copying simple information so I figured out where my error was.
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.
Thank you. I'll have to try that next time instead of looking for soft objects to throw my computer at.
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.
Join our real-time social learning platform and learn together with your friends!