Python在同一行上打印和输入

2024-07-02 09:50:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试执行此操作,但无法执行

有人能帮忙吗

  teamname1 = print(input((plyer1,' Name of your team? '))
  teamname2 = print(input(plyer2,' Name of your team? '))

  print(teamname1)
  print(teamname2)

Tags: ofnameinputyourteamprintteamname2plyer1
2条回答

我不太确定你想用teamname变量做什么。如果你能修改问题/代码,那会很有帮助

至于打印和输入在同一行,我认为这可能是你的目标

print("player1" + " " + input("Name of your team: "))
print("player2" + " " + input("name of your team: "))

另外,网上有很多教程可以提供帮助。一定要先四处看看,然后到这儿来

三个问题:

  1. 第一行包含一个括号太多
  2. input()只接受一个参数,即提示符。如果plyer1是一个 字符串,则必须将其连接起来
  3. 与comment中的相同:print()不返回任何内容,可以 省略,因为input()命令的提示符已被删除 显示

你可能需要这样的东西:

plyer1 = 'parach'
plyer2 = 'amk'

teamname1 = input(plyer1 + ' Name of your team? ')
teamname2 = input(plyer2 + ' Name of your team? ')

print(teamname1)
print(teamname2)

相关问题 更多 >