Home > Enterprise >  I added an operators to give spaces between the two strings but it still doesn't work
I added an operators to give spaces between the two strings but it still doesn't work

Time:12-09

I was trying to make a name input that whenever you type a name it places on the welcome sign of the game. The only problem I am experiencing is that the name I input never has spaces between it, despite that I placed an operator to give it a space

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

and this is the output result: Welcome to the CasinoMikenow go play till get broke

CodePudding user response:

You could always just add a space after 'Casino' and before 'now'. A better way would be to use an fstring.

For example:

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

Edit: Here are a few resources on format string literals:

CodePudding user response:

The space has to be inside the quotes. The spaces you're adding in your expression aren't being used in the string.

"Welcome to the Casino"      name      "now go play till get broke"

vs

"Welcome to the Casino     "   name   "      now go play till get broke"

CodePudding user response:

"Welcome to the casino " name " now go play"

type it like this add a space at the end

Or just add a comma

"Welcome to the casino", name, "now go play"

  • Related