Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (anonymous):

Can someone please help me? I'm brand new to programming and I'm stuck on problem set 0... This is the closest I've come so far: raw_input('Enter your date of birth:') ans = DOB raw_input('Enter your last name:') ans = name print name + DOB It prompts for my DOB, returns it, then stops. Why doesn't it prompt for my name?

OpenStudy (shadowfiend):

Hm. I'm not entirely sure what that code is doing per se. You want to put the result of raw_input into the appropriate variable: DOB = raw_input('Enter your date of birth:') name = raw_input('Enter your last name:') print name + DOB That should work, as raw_input will put the result of what the user types into the DOB variable, and then the second time into the name variable. Then you print both.

OpenStudy (rsmith6559):

raw_input() is a function. A function is a block of code that does a task. When a function finishes, it can return a value. In this case you want to assign the return value to a variable. Assignment is done with a single equal sign. DOB = raw_input('Enter your date of birth:') The 'Enter your...' string is passed into the function. In your code, you were calling the raw_input() function, but then trying to assign what was at that point an undefined variable DOB to ans. In programming, the value of the right side of the "=" is assigned to the left side.

OpenStudy (anonymous):

That's what I tried first! It only asks for my birthday, and then doesn't even print it to the screen...

OpenStudy (anonymous):

oops! never mind... i just hadn't figured out how to use idle properly yet. got it. thank you :)

OpenStudy (shadowfiend):

Good to hear you got it figured out :)

OpenStudy (shadowfiend):

(Might want to give rsmith a medal above if he was helpful ;) )

OpenStudy (anonymous):

raw_input() returns a value so assign it to your variable . DOB = raw_input('say somethin')

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!