将字母分配给变量

Assigning Letters To variable

这是我编写的代码,无论分数是多少,输出总是 "Grade: ",我希望它输出一个等价的字母,但它不会。我试过使用逗号,但似乎没有任何效果。我环顾四周,但找不到问题的答案。

score = input
grade = ""

if score == "5":
    grade == "A"

if score == "4":
    grade == "B"

if score == "3":
    grade == "C"

if score == "2":
    grade == "D"

if score == "1":
    grade = "E"

if score == "0":
    grade == "F"

print("Grade:" + grade)

赋值使用一个等号,比较使用两个等号。

(给变量赋值时,只用一个等号)

您需要:

1- 使用一个运算符= 赋值。

2-通过input()

score赋值
score = input("enter the score (0-5):")
grade = ""

if score == "5":
    grade = "A"

if score == "4":
    grade = "B"

if score == "3":
    grade = "C"

if score == "2":
    grade = "D"

if score == "1":
    grade = "E"

if score == "0":
    grade = "F"

print("Grade:" + grade)