PYTHON 3 我需要帮助。我已经检查过类似的问题。TypeError:输入预计最多 1 个参数

这是我的错误。


Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "main.py", line 21, in welcome

    name2 = input("\nPardon? Did you say",name+"?")

TypeError: input expected at most 1 argument, got 2

这是我的代码。


import random

import time


def welcome():

  #Tutorial

  print("============================================")

  print("Welcome to Blunderberg RPG by ChillingPixel")

  print("The goal is just to have fun and stay alive.")

  print("Yes, No, North, South East, West, are all ")

  print("valid inputs.")

  print("                 Have fun!")

  print("============================================")

# Meeting Old Man Thorley

  time.sleep(5)

  name = input("\nBed and Breakfast Owner:\nWelcome Young traveler what is your name? ")


  time.sleep(2)

  print("Nice to meet you",name,". My name is Old Man Tho—. Wait! Did you say your name was",name,"?")

  

  time.sleep(3)

  name2 = input("\nPardon? Did you say",name+"?")

  if name2 in("Yes,yes,yea,Yea,Yeah,yea,y,Y"):

    game()



def game():

  time.sleep(3)

  print("Testing 123")

我希望用户能够确认这就是他所说的,如果他说是,那么他就会进入游戏()。抱歉,我是 Python 新手


守候你守候我
浏览 297回答 1
1回答

杨魅力

将逗号替换为 + 号name2 = input("\nPardon? Did you say"+name+"?")# or use f-string, same resultname2 = input(f"\nPardon? Did you say {name} ?")您需要连接字符串。通过使用逗号,您将传递两个参数。但 input() 仅接受一个参数
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python