【问题标题】:python3 GPA Calculatorpython3 GPA计算器
【发布时间】:2018-05-16 13:36:37
【问题描述】:

我目前正在尝试创建一个 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)

【问题讨论】:

    标签: python-3.x calculator


    【解决方案1】:

    您正在检查一个全小写的变量是否等于一个带有大写字母的字符串。

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-23
      相关资源
      最近更新 更多