I am very new to this site, and computer science in general, so this question has multiple purposes, can someone check my solution to this very simple Lesson 0 problem, and am I posting this in the correct place, and lastly, is there a more refined way to get spaces in the final output, I feel my solution is clunky. x = raw_input('When were you born?') y = raw_input('What is your last name?') print 'You were born on ' + x + ' ' + 'and, ' + 'your last name is ' + y + '.'
I really wish i could help, but i dont know much about coding, here, let me link someone @iambatman Could you help here at all? or know someone who could?
Hmm maybe @e.mccormick could throw something at ya :)
print 'You were born on ' + x + ' ' + 'and, ' + 'your last name is ' + y + '.' vs. print 'You were born on ' + x + ' ' + 'and, your last name is ' + y + '.' Yes, adding spaces between variables is clunky. Welcome to computers.
You can do ```python x = raw_input('When were you born?') y = raw_input('What is your last name?') print 'You were born on {birthdate} and, your last name is {lastname}.'.format(birthdate=x, lastname=y) ```
Pitamar, thank you for your solution. However I am getting an error when i try to use the format option. This seems like it would be the best way to go about this. I am using python 2.5.4, could that be the issue, or do I have to do something specifically to get the format function to work?
Hm, format works for python 2.6 and greater You can use the this: ``` x = raw_input('When were you born?') y = raw_input('What is your last name?') print 'You were born on %s and, your last name is %s.' % (x, y) ``` I like it less because the order of the variables matters now, unlike with format where you use keywords instead.
Thanks for the advice, the second solution worked perfect in 2.5, however based on your advice I will start using 2.7 instead as I can understand how the order of the variables can become time consuming and more tedious.
Ok, good luck =)
Yah, as you can see they have added improvements. They are not 100% needed for the class, but it is nice to use some of the newer features in case you want to use Python after doing the course work.
Join our real-time social learning platform and learn together with your friends!