gpt4 book ai didi

python - raw_input_wrapper() 从 0 到 1 个位置参数,但 2 个被赋予 Python 3.5

转载 作者:太空宇宙 更新时间:2023-11-04 02:52:34 24 4
gpt4 key购买 nike

我正在尝试制作一款基于文本的冒险游戏,但出现此错误:“0 到 1 个位置参数,但给出了 2 个。”我不确定这意味着什么或如何解决它。有人可以向我解释这个问题吗?谢谢!

##########################################################
##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.")

最佳答案

您向 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)))

关于python - raw_input_wrapper() 从 0 到 1 个位置参数,但 2 个被赋予 Python 3.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43395273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com