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

I'm just on the first problem set (0) and have a question that is probably silly. I was having trouble adding the space between the last name variable and the birth date variable. My solution was to create a variable just for the space which I'm assuming is not the most efficient way to do this. What would be the most concise way to write this?

OpenStudy (e.mccormick):

Try this code and see what you get: a = "hi" b = "there" print (a + " " + b) The principal can be applied in most languages.

OpenStudy (anonymous):

When I type out that code the space appears. But I cannot get the space to appear when doing the exercise. This is what I have - birthday = raw_input ('Enter your date of birth:') name = raw_input ('Enter your last name:') print (name + "" + birthday) and it prints both inputs with no space

OpenStudy (e.mccormick):

I do not see a space between your quotes.

OpenStudy (anonymous):

Got it! So silly, thank you!

OpenStudy (e.mccormick):

The same can be done with any sort of string. Anther place this is useful is for things like: tires = int(raw_input("Tires are $200 each. How many does the customer need? ")) total = float((tires * 200.0 * 1.085) print("With tax the total price is " + total) Now, you would normally do some rounding and sother stuff, but I am just showing where "adding" a string is useful.

OpenStudy (anonymous):

This is very useful information, thank you for your help :)

OpenStudy (rsmith6559):

In Python, if two parts of a print statement are separated by a comma, Python will insert a space: >>> print "Hello", "World" Hello World Just another way.

OpenStudy (e.mccormick):

rsmith6559, that is not always true. In some versions it will also print it out as a tuple when you do that... which is part of why 3.x changed it to a function.

OpenStudy (anonymous):

e.mccormick, would you consider this answer to be correct as well? I took a slightly different approach, and the results are what I wanted them to be in this particular case. Do you see problems that might arise as we move into more complicated programming? x=raw_input('Enter your date of birth:') y=raw_input('Enter your last name:') print y, x

OpenStudy (e.mccormick):

You are just using what this version of the language allows you to do, which is fine.

OpenStudy (anonymous):

i enjoy you guys. I'm really learning from you as if I have always been a computer science student. just through understanding lecture2 ( core element pf programming). but there seem to be a little problem. what does it mean when you try to execute an assignment and a part is highligted preventing you from printing?

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!