I am working on problem set zeroi and It all works except how do you program a space between the question and the answer ?
Should be automatic. When I run my ps0.py the output after specifying both inputs has a space between first and last name.
not exactly, if he says print firstname + lastname it will be one word it should look print firstname, lastname (using a ",") if i get what you meant wrong, i apologize
Thanks nessman, thats what I was missing ,Also when it prints each name there is no space between the question and the answer !
i don't understand what you mean there, could you post your code and perhaps the output your having a problem with?
Oh. I see now. I was using print(first_name,last_name) so the space was there automatically.
string_1=raw_input("Enter your last name please" )
and after please there is no space betmeen the e and the first letter of the name
try string_1=raw_input("Enter your last name please\n" ) keeping the "\n" inside the quotes, this moves the cursor to the next line, there are a few other \commands that I remember seeing in our readings
print string_2 + string_1
nice let mne give that a shot
ok I had to go with + " " + to get the blank space inbetween names
that is odd, print string_2, string_1 gives me a space, its important to figure this out as when your working with anything that isn't a string you can't do that easily. eg: you can't number = 1 print number + " "apple" or at least in 2.7, or maybe I have a bigger problem how about your other problem?
yeah the \n puts the response on the next line
Thanks for the help
you could go print number + " " = apple
oops number + " " + apple
Weird, i get the error TypeError: unsupported operand type(s) for +: 'int' and 'str' its something that seriously gets in my way at times
hmmmm
These will all give you the same output (there are others too): print str(number) + ' some string' print number,'some string' print '%d some string'%number
what does "%d some string "% mean?, i have seen the other methods, but not the last
The %d basically says "I want to put an integer here". The %number at the end tells the interpreter to use the integer stored in the variable "number". I probably should have mentioned that this assumes "number" is an integer. You would use %f for a float, %s for a string, etc. You can also use '{0} some string'.format(number), which doesn't care about the variable type. For more info (and more string formatting options), check out: http://docs.python.org/library/stdtypes.html#string-formatting
Join our real-time social learning platform and learn together with your friends!