Python:类型错误:最多需要输入 1 个参数,得到 3 个[重复]

问题描述 投票:0回答:2

这是我的代码:

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:输入最多需要 1 个参数,得到 3 个

python variables
2个回答
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))

因为有“,”,所以它获取它作为参数并且不会连接字符串

© www.soinside.com 2019 - 2024. All rights reserved.