【问题标题】:I added an operators to give spaces between the two strings but it still doesn't work我添加了一个运算符来在两个字符串之间留出空格,但它仍然不起作用
【发布时间】:2022-12-12 14:49:22
【问题描述】:

我试图输入一个名称,每当你输入一个名称时,它就会放在游戏的欢迎标志上。我遇到的唯一问题是我输入的名称之间从来没有空格,尽管我放置了一个运算符来给它一个空格

name = input("what is your name:")
print("Welcome to the Casino" + name + "now go play till get broke")

这是输出结果:Welcome to the CasinoMikenow go play till get broke

【问题讨论】:

  • 你是什​​么意思“运营商给它一个空间”, 你没有添加任何空间

标签: python string input output letter-spacing


【解决方案1】:

您始终可以在“Casino”之后和“now”之前添加一个空格。更好的方法是使用 fstring。

例如:

name = input("what is your name: ")
print(f'Welcome to the Casino {name} now go play till get broke')

输出:

what is your name: Jordan
Welcome to the Casino Jordan now go play till get broke

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 2022-01-17
    • 2023-02-01
    • 2019-09-05
    • 2015-02-28
    相关资源
    最近更新 更多