Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 10 Online
OpenStudy (anonymous):

I am working on problem set zeroi and It all works except how do you program a space between the question and the answer ?

OpenStudy (anonymous):

Should be automatic. When I run my ps0.py the output after specifying both inputs has a space between first and last name.

OpenStudy (anonymous):

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

OpenStudy (anonymous):

Thanks nessman, thats what I was missing ,Also when it prints each name there is no space between the question and the answer !

OpenStudy (anonymous):

i don't understand what you mean there, could you post your code and perhaps the output your having a problem with?

OpenStudy (anonymous):

Oh. I see now. I was using print(first_name,last_name) so the space was there automatically.

OpenStudy (anonymous):

string_1=raw_input("Enter your last name please" )

OpenStudy (anonymous):

and after please there is no space betmeen the e and the first letter of the name

OpenStudy (anonymous):

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

OpenStudy (anonymous):

print string_2 + string_1

OpenStudy (anonymous):

nice let mne give that a shot

OpenStudy (anonymous):

ok I had to go with + " " + to get the blank space inbetween names

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

yeah the \n puts the response on the next line

OpenStudy (anonymous):

Thanks for the help

OpenStudy (anonymous):

you could go print number + " " = apple

OpenStudy (anonymous):

oops number + " " + apple

OpenStudy (anonymous):

Weird, i get the error TypeError: unsupported operand type(s) for +: 'int' and 'str' its something that seriously gets in my way at times

OpenStudy (anonymous):

hmmmm

OpenStudy (anonymous):

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

OpenStudy (anonymous):

what does "%d some string "% mean?, i have seen the other methods, but not the last

OpenStudy (anonymous):

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!