Confused by Lec 4 example code: When trying to run the withinepsilon code on python 3.3 i keep getting a syntax error for the "Print withinepsilon(2,3,1)" line. I tried using the following: "Print(withinepsilon,2,3,1)" but still get a syntax error. What am I doing wrong?
Try print(withinepsilon(2,3,1)).
Sorry, @jonghyun I mistyped my initial quesiton. I have already tried that syntax and it didn't work. here is the copy/paste of my code: def withinEpsilon(x, y, epsilon): """x,y,epsilon ints or floats. epsilon > 0.0 returns True if x is within epsilon of y""" return abs(x - y) <= epsilon print(withinEpsilon(2,3,1)) SyntaxError: invalid syntax ---print operator is highlighted
That's strange. I just copy&pasted your code as it is into IDLE and a run just printed "True", without any error.
One of the major changes in the 3.x line is print. There are other changes in division that will make some of the other parts of the classes not work as intended. That is why it is suggested you use the 2.x line, even the latest 2.7.x, rather than 3.x. If you know python, the issues are not that bad. If you are just learning, well, there can be issues.
I ran the code in Python 2.7 and in 3.2. Both times the program ran without error and printed "True".
2.7 has support for the new print funtion. That is one of the things 2.7 does as the changeover version.
That's right but abkhan90 writes that he uses 3.3 (which he should not for the course) and it gives him an error message. I don't know of any change in the print function syntax from 3.2 to 3.3 and didn't find any in the python-docs. http://docs.python.org/3/whatsnew/3.3.html I also just tried python2.6, the code worked.
Join our real-time social learning platform and learn together with your friends!