Hello everyone,
I have been working with python now for a few days now and am moving at a decent clip. One of the things that has been constantly tripping me up are inconsistent tabs, spaces, and other such errors in indentation.
Coming from Java, I understand the importance of keeping things consistent since I (thankfully) no longer need to sprinkle semicolons everywhere.
However, I think I might have met my match with this lesson:
https://www.codecademy.com/courses/learn-python-3/lessons/python-control-flow/exercises/boolean-operators-not/
The code I entered is:
def graduation_reqs(gpa, credits):
if (gpa >= 2.0) and (credits >= 120):
return "You meet the requirements to graduate!"
if (gpa >= 2.0) and not (credits >= 120):
return "You do not have enough credits to graduate."
if not (gpa >= 2.0) and (credits >= 120):
return "Your GPA is not high enough to graduate."
if not (gpa >= 2.0) and not (credits >= 120):
return "You do not meet either requirement to graduate!"
After fiddling with my code and eventually giving up, I decided to look at the correct answer which is:
def graduation_reqs(gpa, credits):
if (gpa >= 2.0) and (credits >= 120):
return "You meet the requirements to graduate!"
if (gpa >= 2.0) and not (credits >= 120):
return "You do not have enough credits to graduate."
if not (gpa >= 2.0) and (credits >= 120):
return "Your GPA is not high enough to graduate."
if not (gpa >= 2.0) and not (credits >= 120):
return "You do not meet either requirement to graduate!"
Normally, I’ve been able to figure out my tab and spacing issues by comparing each line but this time I don’t see any differences between my spaces, tabs, and indentation and sadly have met my match.
First, how do I resolve my tab errors in this lesson and secondly what are some good keyboard entry habits that I can do to ensure that my entries are formatted the way the compiler expects?
I appreciate any help and advice given. Thank you!
Edit: so after putting my code into this forum post, I can see the issue clear as day. Why does it look different here then in the lesson?
Here is a screenshot of the same code that I see on my web browser: