2017-04-13 73 views
1

我想製作一個基於文本的冒險遊戲,並且出現此錯誤:「0到1個位置參數但給出了2個。我不確定它是什麼意思或如何解決它。有人可以向我解釋這個問題嗎?謝謝!raw_input_wrapper()需要從0到1的位置參數,但需要2個給定的Python 3.5

########################################################## 
##farm game 
########################################################## 


player_name = input("What's your name? ") 
print ("Hello {}".format(player_name)) 

print ("You wake up to the sound of your mother calling from the kitchen: 
     {}" .format(player_name), ", wake up! I need your help in the kitchen!") 
ch1 = str(input("Will you go downstairs? ")) 

# kitchen 
if ch1 in ['y', 'Y', 'Yes', 'YES', 'yes']: 
    print("You go downstairs.") 
    ch2 = str(input("Your mother is in front of the oven, preparing to make 
       a loaf of bread. She turns to look at you and says: {}" 
       .format(player_name), ", I need three eggs. Please go fetch 
       the eggs from the barn.")) 
if ch2 in ['y', 'Y', 'Yes', 'YES', 'yes']: 
    print("You leave the kitchen and enter the large back yard. You are in 
     a fenced in area. Three pigs are rooting around in the fresh spring 
     grass, snorting and snuffling. At the end of the yard is the barn, 
     where the cows and horses live. To your right is the kitchen coop. 
     You can hear the soft clucking of chickens from inside.") 

# no kitchen 
else: 
    print("You look around the room.") 
+0

我如果和打印語句縮進,但我沒有抄在這裏粘貼它。所以我不認爲這是一個語法問題。 – Jane

+0

我清理了格式。 – gregb212

回答

1

你傳入的參數太多爲input()。請參見下面的例子:

>>> x = input() 
hello world 
>>> print(x) 
hello world 


>>> x = input("Say hello: ") 
Say hello: hello world 
>>> print(x) 
hello world 


>>> x = input("first argument", "second argument") 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: input expected at most 1 arguments, got 2 

給玩家的名字添加到您的輸入,移動.format到字符串的結尾:

ch2 = input("Your mother is in front of the oven, preparing to make a loaf of bread. She turns to look at you and says: {} , I need three eggs. Please go fetch the eggs from the barn.".format(player_name))) 
+0

解決了這個問題!謝謝。 – Jane

相關問題