connorling
connorling

Reputation: 75

Python if statement result not being printed

I have this simple python program involving entering a given mark for a subject and then seeing what range is falls under in order to return the appropriate grade


# ask user for the subject code 
user_input = input("Enter subject code: ")
subject_code = user_input

# ask user for the mark 
user_input = input("Enter mark: ")
subject_mark = int(user_input)

print("RESULT: ")
print("Subject code: " + subject_code)
print("Mark: " + str(subject_mark))

if subject_mark <100 and subject_mark >85:
  print("Grade: HD")
elif subject_mark <84 and subject_mark >75:
  print("Grade: D")
elif subject_mark <74 and subject_mark >65:
  print("Grade: C")
elif subject_mark <64 and subject_mark >50:
  print("Grade: P")
elif subject_mark <49 and subject_mark >0:
  print("Grade: F")
else:
    print("invalid")

however, when i run this program it doesnt print the Grade. It only prints this

Enter subject code: MATH111
Enter mark: 85
'RESULT: 
Subject code: MATH111
Mark: 85

Where as it should print this

Enter subject code: MATH111
Enter mark: 85
'RESULT: 
Subject code: MATH111
Mark: 85
Grade: HD

Any help is much appreciated

Upvotes: 1

Views: 87

Answers (2)

Thunderqz1
Thunderqz1

Reputation: 16

Use <= or >= instead of > or <

Upvotes: 0

Savrona
Savrona

Reputation: 333

You should use => instead of >.

if subject_mark <100 and subject_mark >=85:
  print("Grade: HD")
elif subject_mark <84 and subject_mark >=75:
  print("Grade: D")
elif subject_mark <74 and subject_mark >=65:
  print("Grade: C")
elif subject_mark <64 and subject_mark >=50:
  print("Grade: P")
elif subject_mark <49 and subject_mark >=0:
  print("Grade: F")
else:
    print("invalid")

Upvotes: 1

Related Questions