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

How come when running my code below, problem set #0, the user is asked twice for his birth date and last name? print raw_input ("Enter your date of birth:") x = raw_input ("Enter your date of birth:") print raw_input ("Enter your last name:") y = raw_input ("Enter your last name:") print (y + " " + x)

OpenStudy (anonymous):

The function raw_input is printing Enter your date of birth already. You don't have to use the print command in front of it, unless you just want to print out what the user puts as an input. x = raw_input("Enter your date of birth") translates to... Prompt the user to enter their date of birth and assign that input into the variable x

OpenStudy (anonymous):

Okay, that fixed the part where it printed what the user puts in as input. But it still asks me to type in both my date of birth and last name twice, before printing them in the desired order. Is there another problem with the code? raw_input ("Enter your date of birth:") x = raw_input ("Enter your date of birth:") raw_input ("Enter your last name:") y = raw_input ("Enter your last name:") print (y + " " + x)

OpenStudy (anonymous):

you can take out the 1st and 3rd line from above.

OpenStudy (anonymous):

@JPinkman your code asks for input twice ``` raw_input ("Enter your date of birth:") ``` This line asks for your birthday but do nothing. ``` x = raw_input ("Enter your date of birth:") ``` But this line asks for for your birthday AND assign it to the variable `x`. That why you were asked twice. Solution: ``` x = raw_input ("Enter your date of birth:") y = raw_input ("Enter your last name:") print (y + " " + x) ``` Good luck!

OpenStudy (anonymous):

Problem solved. Thanks!

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!