if score <=30:
print = "You have scored:" + score + ":("
else score > = 31 and < = 60
print = "You have scored:" + score + ":/"
elif score < = 61
print = "You have scored:" + score + ":)"
我正在python中进行测验,我需要它,以便当分数介于0-30,30-60和60+之间时,会显示不同的消息,尽管我尝试了上面的代码并且它一直说无效的语法
答案 0 :(得分:0)
这是因为得分变量是一个整数,所以你不能那样打印它。试试这个,打印的东西应该放在括号中,而不是“=”。在if语句之后还应该有一个“:”。试试这个:
if score <=30:
print("You have scored:" + str(score) + ":(")
elif score >= 31 and score <= 60:
print("You have scored:" + str(score) + ":/")
elif score <= 61:
print("You have scored:" + str(score) + ":)")
答案 1 :(得分:-2)
else score > = 31 and score <= 60
需要
elif score > = 31 and score <= 60:
你需要在最后一个elif上加:
。而你的印刷陈述是错误的。语法为print 'hello'
或print('hello')
,具体取决于python版本。你应该看看初学python语法的东西