Synax错误打印[巨蟒]
问题描述:
我有我的代码的麻烦,当我运行此我得到一个语法错误“打印”Synax错误打印[巨蟒]
word1 = input("Words: ")
characters = len(word1)
listOfStuff = str(word1)
strip = ""
x = 1
while not characters > 140 - 11:
word = input("Words: ")
if characters <= 140 - 11:
listOfStuff = listOfStuff + ' ' + str(word)
characters = characters + len(word) - 1
elif characters > 140 - 11:
strip = len(word)
break
finalLength = len(listOfStuff)
print(listOfStuff.rstrip(strip)
print(finalLength)
当我做错了什么?
答
你错过了一个右括号:
print(listOfStuff.rstrip(strip)
# --------^
答
如果您正在使用
Python2.x
1)您可能需要使用
raw_input("Words: ")
代替
input("Words: ")
2)print
不指望括号
print listOfStuff.rstrip(strip)
print finalLength
Python3
1)的Martijn皮特斯的前面回答持有好。你缺少一个右括号
print(listOfStuff.rstrip(strip))
,而不是
print(listOfStuff.rstrip(strip)
+0
在Python2的情况下,括号不伤害,所以这是确定要离开他们(至少如果我只打印一个项目)。 – glglgl
使用vim和类型':DoMatchParen' –