【问题标题】:Python print and input on same linePython在同一行打印和输入
【发布时间】:2020-06-05 21:50:48
【问题描述】:

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

有人可以帮忙吗?

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

  print(teamname1)
  print(teamname2)

【问题讨论】:

  • print 返回None,因此您将None 分配给teamname1teamname2。删除input()s 周围的print()

标签: python input printing data-analysis


【解决方案1】:

三个问题:

  1. 第一行包含一个括号太多
  2. input() 只接受一个参数,即提示。如果 plyer1 是 字符串,你必须连接它
  3. 与注释相同:print() 不返回任何内容,并且可以 省略,因为 input() 命令的提示已经 显示。

你可能需要这样的东西:

plyer1 = 'parach'
plyer2 = 'amk'

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

print(teamname1)
print(teamname2)

【讨论】:

    【解决方案2】:

    我不确定您要对 teamname 变量做什么。如果您可以修改问题/代码,那将有很大帮助。

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

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

    附:有很多在线教程可以提供帮助。一定要先环顾四周,然后来这里。

    【讨论】:

    • player 1 是我想在问题之前打印的字符串。我可以看到我做错了什么。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多