Python Forum
Help? Letter Grade assignment..
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help? Letter Grade assignment..
#1
I need an error message to display to the user if they try to enter a score over 100 and I need to use the sys.exit() to exit the program gracefully if any errors are detected. I need to do this in an if statement. I can't figure this out, I'm a total noob. Help please..


name = input("Please enter your First and Last Name: ")
score = int(input("Enter your first exam score: "))
score2 = int(input("Enter your second exam score: "))
score3 = int(input("Enter your third exam score: "))

average = (score + score2 + score3) // 3

if average >= 100:
    print("Error")
    sys.exit()
elif average >= 90 and average <= 100:
    print("You received an A.")
elif average >= 80 and average < 90:
    print("You received a B.")
elif average >= 70 and average < 80:
    print("You received a C.")
elif average >= 60 and average < 70:
    print("You received a D.")
else:
    print("You received an F.")
        
print("Report Card")
print("Name:", name)
print("You scored a", score, "on your first exam.")
print("You scored a", score2, "on your second exam.")
print("You scored a", score3, "on your third exam.")
print("Your average score is" ,average,"percent.")
Reply
#2
What's wrong with what you have? (Other than probably wanting > 100 instead of >= 100.)
Reply
#3
You could put in if statement after every variable that will ask for same input IF input does not meet the criteria, in this case its a number being over 100.

score = int(input("Enter your first exam score: "))
if score > 100:
   print("score can not be over 100!")
   score = int(input("Enter your first exam score: "))

score2 = int(input("Enter your second exam score: "))
if score2 > 100:
   print("score can not be over 100!")
   score2 = int(input("Enter your second exam score: "))

score3 = int(input("Enter your third exam score: "))
if score3 > 100:
   print("score can not be over 100!")
   score3 = int(input("Enter your third exam score: "))
Reply
#4
if average >= 100: this means if average is HIGHER THAN or EQUALS TO 100
What you should use here is just > instead of >=
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Method to calculate average and grade ajitnayak1987 8 6,158 Apr-28-2022, 06:26 AM
Last Post: rayansaqer
  Non Grade/School Help - PLEASE gbyrne12 8 2,982 Jun-19-2021, 07:31 PM
Last Post: snippsat
  Calculating Grade Average IstvanCH 5 4,951 Jan-27-2019, 04:42 PM
Last Post: aakashjha001
  Student grade program help debug ccm1776 3 5,040 Nov-14-2018, 02:41 AM
Last Post: stullis
  Grade Loop dtweaponx 8 12,255 Oct-17-2017, 02:01 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020