2016-10-18 96 views
-1

這是我的代碼:的Python:類型錯誤:輸入預計最多1個參數,得到了3

print("Hello, what's your name?") 
myName = sys.stdin.readline() 
Join = input("Would you like to play a game, yes or no?").lower() 
if Join.startswith('y'): 
    print("Fine, you can play.") 
else: 
    print("Ok, goodbye.") 
    sys.exit() 
Color = input("So, first question. What's your favorite colour, 
or do you have none?").lower() 
if Color.startswith("n"): 
    Thanks = input("Didn't expect much from you, good job", myName, 
" Say thanks, I complimented you!").lower() 
else: 
    print("Having a favorite colour is the wrong answer, try again.") 
    sys.exit() 
if Thanks.lower() == 'thanks': 
    print("NEVER SAY THANKS!") 
    sys.exit() 
else: 
    Continue = input("Well done, you didn't say THANKS. 
    Do you wish to continue, yes or no?").lower() 
if Continue.startswith('y'): 
    print("Sure let's continue then.") 
else: 
    print("Too bad, you HAVE to continue!") 
    sys.exit() 

我是新來編程,而我只是做一個「笑話」的代碼進行練習。

Thanks = input("Didn't expect much from you, good job", myName, " Say thanks, I complimented you!").lower() 

的錯誤是::但我一直在這條線得到一個錯誤

TypeError: input expected at most 1 arguments, got 3

+1

你可以加入(串連)的字符串。逗號語法僅適用於「打印」功能,該功能會自動爲您加入。 – Aurora0001

回答

1

輸入需要一個參數,您所提供的3

來連接字符串,您可以使用+而不是,

Thanks = input("Didn't expect much from you, good job "+ myName + +" Say thanks, I complimented you!").lower()

1

而是執行此操作:

Thanks = input("Didn't expect much from you, good job {} Say thanks, I complimented you!".format(myName)) 

因爲「」,它得到它作爲參數,並且不與'+'在連接字符串

+0

雖然這可能是理想的解決方案,但向OP解釋它的功能可能很有幫助,因爲它們顯然是初學者。 – Aurora0001

相關問題