为什么无论我的分数是多少,我都会收到相同的输出?
我正在做这个“测验”,我正在尝试添加一个评分系统
#starting score
score = 0
if Question_1 in ("Cheetah", "CHEETAH", "cheetah"):
score =+ 1
else:
pass
if Question_2 in ("Sailfish", "SAILFISH", "sailfish"):
score =+ 1
else:
pass
if Question_3 in ("Peregrine Falcon", "peregrine falcon", "PEREGRINE FALCON", "pf"):
score =+ 1
else:
pass
if Question_4 in ("A decade", "Decade", "DECADE", "decade"):
score =+ 1
else:
pass
if Question_5 in ("Centimetre", "Centimetres", "CENTIMETRE", "CM", "cm", "centi", "centimetre"):
score =+ 1
else:
pass
#once all answers have been checked display result
if score == 0:
print("your result was 0/5, very bad!")
elif score == 1:
print("your result was 1/5, bad!")
elif score == 2:
print("your result was 2/5, mid!")
elif score == 3:
print("your result was 3/5, good!")
elif score == 4:
print("your result was 4/5, very good!!")
elif score == 5:
print("your result was 5/5, EXCELLENT!!")
else:
pass
当我测试我的代码时,如果我的分数是 0,它输出为 0,但如果我的分数是 1、2、3、4 或 5,它输出就好像我只回答了一个正确的问题,有人知道为什么吗?我也想知道是否还有其他方法可以做评分系统,例如使用“while循环”?
回答
您需要的运算符是+=。=+只是一个=带符号的正整数。