Noah E
Noah E

Reputation: 3

python3 GPA Calculator

I am currently attempting to create a GPA calculator where the user types in his grade as a letter and it should convert into a number. However, it is not running the first if statement while running the break statement. I have searched for answers and none have been able to fix the code. How can I alter or change the if statement so it appends to the list? Here is the code:

yourGrade = {}

while True:
    score = str(input("Enter your letter grades: "))
    if score.lower() == 'A' or score.lower() == 'A+' or score.lower() == 'A-':
        yourGrade.append(int(4))
        print(yourGrade)
    if score.lower() == 'done':
        break


print(yourGrade)

Upvotes: 0

Views: 169

Answers (1)

Luke Ramsden
Luke Ramsden

Reputation: 734

You are checking if a variable in all lower-case is equal to a string literal with capitals in it.

Try this:

if score.lower() == 'a' or score.lower() == 'a+' or score.lower() == 'a-':

Upvotes: 1

Related Questions