Python 3.x python3 GPA计算器

Python 3.x python3 GPA计算器,python-3.x,calculator,Python 3.x,Calculator,我目前正在尝试创建一个GPA计算器,用户在其成绩中键入字母,并将其转换为数字。但是,在运行break语句时,它不会运行第一个if语句。 我已经搜索了答案,但没有人能够修复代码。如何更改if语句,使其附加到列表中? 代码如下: yourGrade = {} while True: score = str(input("Enter your letter grades: ")) if score.lower() == 'A' or score.lower() == 'A+' or

我目前正在尝试创建一个GPA计算器,用户在其成绩中键入字母,并将其转换为数字。但是,在运行break语句时,它不会运行第一个if语句。 我已经搜索了答案,但没有人能够修复代码。如何更改if语句,使其附加到列表中? 代码如下:

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)

您正在检查所有小写形式的变量是否等于包含大写字母的字符串文字

试试这个:

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