[英]I added an operators to give spaces between the two strings but it still doesn't work
我試圖輸入一個名稱,每當你輸入一個名稱時,它就會放在游戲的歡迎標志上。 我遇到的唯一問題是我輸入的名稱之間從來沒有空格,盡管我放置了一個運算符來給它一個空格
name = input("what is your name:")
print("Welcome to the Casino" + name + "now go play till get broke")
這是 output 結果: Welcome to the CasinoMikenow go play till get broke
您始終可以在“Casino”之后和“now”之前添加一個空格。 更好的方法是使用fstring 。
例如:
name = input("what is your name: ")
print(f'Welcome to the Casino {name} now go play till get broke')
Output:
what is your name: Jordan
Welcome to the Casino Jordan now go play till get broke
編輯:這里有一些關於格式字符串文字的資源:
他們有很多方法可以解決這個問題,例如:
您可以在“賭場”一詞之后和“現在”一詞之前添加空格
print("Welcome to the Casino" + name + "now go play till get break")
您可以使用“,”而不是使用“+”來分隔 print 語句中的多個值:
print("Welcome to the Casino", name, "now go play till get break")
“歡迎來到賭場”+名字+“現在go玩”
像這樣輸入最后加一個空格
要不就
name = input("what is your name: ")
print(f"Welcome to the Casino {name}")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.