【发布时间】:2016-01-11 20:25:11
【问题描述】:
这是一个非常简单的想法,你输入你的测试分数,如果你得到了 70% (35/50) 以上的分数,你可以做 1 分的更正,基本上给你 100%。如果你得到低于 70%,你可以做 1/2 个点的更正。
这给了我一个无效的语法,并将光标放在最后一个 " 和 ) 之间
score = input("How many problems did you get right on the test?")
maxscore = 50
passscore = 35
wrong = (maxscore - score)
if (score > passscore):
print ("You will get a 100%")
if (score < passscore):
print("You can get"(wrong)"% back with text corrections")
如果我在这里看起来真的很愚蠢,我很抱歉。
【问题讨论】:
-
您需要将
wrong附加到其两侧的其他两个字符串中。使用 + 或 ,。例如。print("Hello" + "World") -
相关(虽然不完全是骗局):stackoverflow.com/questions/13945749/…
-
@TigerhawkT3 因为
print ("You will get a 100%")和input()函数,我认为OP使用的是Python 3。 -
@KevinGuan - 从技术上讲,您可以在 Python 2
print语句中使用括号。print ('hi')之类的东西在 Python 2 和 3 中产生相同的结果,但print ('hi', 'there')在 Python 2 中产生元组('hi', 'there')在 Python 3 中产生字符串'hi there'。此外,input()存在于 Python 2 中,并将评估将输入的字符串转换为int或float或其他 - Python 3 需要转换字符串。 -
@KevinGuan - 不,那不是
tuple。括号仅影响分组。1,是tuple,而(1)是int。
标签: python if-statement syntax-error