将字母分配给变量

时间:2017-11-06 03:15:42

标签: python variables variable-assignment letter

这是我所制作的代码,无论分数是什么,输出总是"等级:",我希望它输出一个符合条件的字母,但它不会。我试过用逗号但似乎没什么用。我一直在寻找,但找不到我的问题的答案。

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)

2 个答案:

答案 0 :(得分:2)

分配使用单个等号,比较使用两个。

(当你分配变量时,只使用一个等号)

答案 1 :(得分:2)

你需要:

1-使用一个运算符=进行分配。

2-通过score

将值分配给input()
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)