簡體   English   中英

Synax錯誤打印[python]

[英]Synax error print [python]

我的代碼有問題,運行此代碼時出現語法錯誤“打印”

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 Pieters的答案很好。 您缺少右括號

print(listOfStuff.rstrip(strip))

代替

print(listOfStuff.rstrip(strip)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM