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

On problem Set 0 I can not figure out how to combine the first and last name questions to print the full name. When I try to assign variable to the questions I am told I have invalid syntax. Can I just copy someone's homework so I might have a clue?

OpenStudy (anonymous):

I simply set my variables as x and y and used "print y,x" to show my result.

OpenStudy (e.mccormick):

What is the code? Without it, can't see your syntax.

OpenStudy (anonymous):

i don't know if this can be of some help; this is how I did mine and I don't really know if I did the right thing but all I know is that I got the result. check my code below: a = raw_input ('enter your date of birth') print a b = raw_input ('enter your last name') print b print (a) + (b)

OpenStudy (anonymous):

Please attach your code so we can give you better guidance. Without seeing your code, I would agree with @oyelands. Two strings can be concatenated (meaning, joined together) with the + operator.

OpenStudy (anonymous):

@markNehus. tanx a million. now a new challenge:I need you to explain how I can get started with my problem set 1(paying off credit card debt). I’m not getting anything done. (and which lecture could be more helpful: vedio 3 or 4?)Please make explanation and code simpler. I’m new in computer science field. @WhiteGuy492: I wouldn't know if setting your variable as x,y without attaching raw_input (code) will yield result. but if you came up with something quite different and simpler than mine and the end result is justifiable. please carry someone along.

OpenStudy (e.mccormick):

@oyelands Open your own question on things when you have your own problem. Each question is to help the original asker.

OpenStudy (anonymous):

When I do the print (a) + (b) I get the string run together with no space, I think this is the original issue. I solved this by print (a) + (' ') + (b) I don't know how correct that is, but it is a trick I learned when dealing with concatenation in Excel. And it seems to work. Does anyone know of a better way?

OpenStudy (e.mccormick):

Concatenation is designed to join things exactly so that you can do things without a space when needed. That is why adding a space manually is required in concatenation.

OpenStudy (anonymous):

So, then, is my solution "print a + ' ' + b" the correct way to insert the space? or is there a more elegant solution? I ask because I want to build good habits from the beginning and not have to try and overcome bad ones.

OpenStudy (anonymous):

oh thanks! @markNehus.

OpenStudy (e.mccormick):

garanw, that is how people end up doing it in basically every language.

OpenStudy (anonymous):

x = raw_input('Enter your name:') y = raw_input('Enter your date of birth: ') print 'Your name is ' + str(x) + ' and your date of birth is ' + str(y) is what i came up with....

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!