【问题标题】:HI, I am new and don't really know what I am doing could someone help me with my project [duplicate]嗨,我是新手,我真的不知道我在做什么有人可以帮助我完成我的项目[重复]
【发布时间】:2021-01-31 17:58:19
【问题描述】:

这是我运行它时给我的。

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    name2 = int(input("What whould you like me to call you",  name1))
TypeError: input expected at most 1 argument, got 2

这是我的工作

#Birthday
feeling = input("Hello, how are you doing? ")
print("Good to hear you're doing well")
name1 = input("And what is your name: "  )
print("Lovely name ;) ")
name2 = int(input("What would you like me to call you",  name1))
print("Welcome to Birthday Plaza where we do all the work for you", name2)

【问题讨论】:

  • 你为什么要输入 name2??
  • 阅读文档:input 只接受一个参数。您必须为提示连接所需的字符串。用逗号分隔片段不起作用。

标签: python


【解决方案1】:

你可以做你想做的一种方式是这样的:

text = "What would you like me to call you, " + name1 + "?\n"
name2 = input(text)

input 不像print 那样工作。它只能接受一个论点。您可以准备好您的问题并将其保存在一个变量中,然后使用它调用input

【讨论】:

  • 非常感谢您的帮助。
【解决方案2】:

输入最多需要 1 个参数,得到 2 个

另外,不要强制转换为 int。

这应该可行:

name2 = input("What would you like me to call you")

【讨论】:

  • 非常感谢您的帮助。
【解决方案3】:

这样做

a = "What would you like me to call you"
a += name1
name2 = input(a)

name2 = input("What would you like me to call you " + name1)

【讨论】:

  • 非常感谢您的帮助。
猜你喜欢
  • 2021-02-08
  • 1970-01-01
  • 2023-04-02
  • 2022-01-07
  • 2022-11-17
  • 2017-04-22
  • 2020-11-20
  • 2021-01-05
  • 2022-06-16
相关资源
最近更新 更多