EOF error

" Write an if statement that checks if the student has enough credits to graduate. If they do, print the string:

“You have enough credits to graduate!”
Can a student with 120 credits graduate from Calvin Coolidge’s Cool College?.

My code is as seen below;

user_credit = input ("Enter credit score")
if user_credit >= 120:
  print("You have enough credits to graduate")
else:
  print("Sorry, you didn't make it this time, but that's ok. There's another session")

THE PROBLEM: It keeps showing me EOF error pointing at line one. Please help. I have compared with the solution, and we used different approach (see attached) so it didn’t help me.

PS: My code starts from line 10 , and the solution started from line 13

If I’m not mistaken, they’re asking you to build up towards writing a function with one parameter “credits” where the logic is:

if credits >= 120:
     return "You have enough credits to graduate!"

print(graduation_reqs(120))

Where one passes through the arg for credits…whatever it may be, 120, 125, 94, etc. and a value is returned.

What you’ve written doesn’t match b/c the lesson & solution aren’t asking for user input. It’s asking to define a variable, credits = 120
then an if statement, if credits >=120 print("blahblahblah")

def greater_than(x, y):
  if x > y:
    return x
  if y > x:
    return y
  if x == y:
    return "These numbers are the same"
#print(greater_than(4, 9))       

def graduation_reqs(credits):
  if credits >= 120:
     return "You have enough credits to graduate!"

print(graduation_reqs(120))

Your code throws an “‘>=’ not supported between instances of ‘str’ and ‘int’” b/c you’re trying to use a comparison operator to compare a str and int.

Brilliant Lisa… thanks a lot. :slightly_smiling_face:

1 Like

Sure thing.
When you get error messages, it’s always/usually helpful to google them and then look at the Python docs to get a more thorough explanation.

And, your code would have worked if you had tweaked it a bit and cast the input as an int:
ex:

user_credit = int(input("Enter credit score"))

Because, again, you can compare integers w/intergers and you can compare strings w/strings, but you cannot use a comparison operator with an int to a str.

See:
https://docs.python.org/3/tutorial/controlflow.html

Also, I think they may have changed up the instructions on this section of the path(?) b/c if I go back and look at my code, I’ve written a function…which is not expressly conveyed in the instructions. :woman_shrugging:

1 Like