1

I am beginning to learn python and doing a practice program.

I've inserted the code below.

av_grade = int(input ("What is your average grade? "))

if(av_grade >= 70):
  absences = int(input ("How many absences do you have? "))
  if (absences <= 5):
    credits = int(input ("How many credits have you earned? "))
  else: 
    print("You are not eligible for privileges")
    if (credits >= 17):
      print("You are eligible for senior privileges")
    elif (credits >= 11):
      print("You are eligible for junior privileges")
    else:
      print("You are not eligible for privileges")
else:
  print("You are not eligible for privileges")

Looking for any help if possible about what I can do to fix this.

1
  • Please include in the question what input you're providing to the program, and the full error message including the stack trace - see minimal reproducible example.
    – kaya3
    Oct 7, 2021 at 23:57

1 Answer 1

4

You are accessing the variable credits before you set it to a value and credits is a built in variable:

C:\Temp>test.py
What is your average grade? 89
How many absences do you have? 9
You are not eligible for privileges
Traceback (most recent call last):
  File "C:\Temp\test.py", line 9, in <module>
    if (credits >= 17):
TypeError: '>=' not supported between instances of '_Printer' and 'int'


C:\Temp>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:04:37) [MSC v.1929 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> type(credits)
<class '_sitebuiltins._Printer'>
>>>

If absences > 5 then you access credits before you set it.

Bobby

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.