PDA

View Full Version : How to create space when printing two variables?



davorp
07-04-2018, 04:35 PM
This is maybe a basic question, but it has been giving me a headache. How to I make space when printing two variables.

Example:


FirstName = input("What's your first name? ")

LastName = input("What's your last name? ")
print ("Hello: )", FirstName + LastName)

ozzsurf
07-04-2018, 05:13 PM
you can read here


https://stackoverflow.com/questions/9969684/how-do-i-add-space-between-two-variables-after-a-print-in-python

voyager1972
07-04-2018, 05:48 PM
print ("Hello " + FirstName +" " + LastName )

davorp
07-04-2018, 06:59 PM
I have tried that, but reports an error, unexpected syntax “ “ .

saintomer1866
07-04-2018, 09:06 PM
it may depend on which version of python you are using
but try this;

firstName = raw_input("What's your first name? ")
lastName = raw_input("What's your last name? ")
print "Hi there, " + firstName + " " + lastName + "!"

St.O

mrdude
07-04-2018, 10:01 PM
str1 = "Firstname"
str2 = " "
str3 = "Lastname"
fullname = str1 + str2 + str3
print fullname


Something like that should work.


Also look at your last line: print ("Hello: )", FirstName + LastName)

You have got a bracket inside your brackets ()) - you aren't closing the brackets like that, should be like this (()) - do you know what I mean?

Also it should be more like this:

string = "Hello " + FirstName + " " + LastName
print string

davorp
08-04-2018, 09:50 AM
Thanks everyone.