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

How do I get it to ask for Last name, First name but print First name, Last name Pset0?

OpenStudy (anonymous):

I mean, that is the entire problem set. You are supposed to figure that out. Refer to the link. Learn how to ask the user for data, then ask the user for the datum you need, then create a code that uses the input data and arranges it in the proper order.

OpenStudy (anonymous):

I've figured out most of it. That's my point. I'm stuck on reversing the order. I have referred to the Python wiki, doesn't seem to say anything about reversing order.

OpenStudy (anonymous):

Better suggestion for reference material?

OpenStudy (anonymous):

Assign last name's raw data to a variable. Do the same to first name and then write a code that generates them in the correct order. So the last line should be something akin to print b , a

OpenStudy (anonymous):

I did that. And actually the last line I have right now is print answerb, print answer but it's not coming out right. Thanks though! I'll keep trying.

OpenStudy (anonymous):

Don't forget that there is reading that accompanies this course. Post your code. Let me have a gander at it.

OpenStudy (anonymous):

I know there's reading, but for the first lecture all I saw was the problem set and referring to the input/output section of the Python wiki. Give me a second and I'll post the code.

OpenStudy (anonymous):

Sounds good. I reread my responses. Sorry if I sound harsh. I kind of am. sorry.

OpenStudy (anonymous):

Ok here's what I was starting with: a = "Enter your last name:" b = "Enter your first name:" print a, b

OpenStudy (anonymous):

Should I not be assigning these to variables? Is this where I'm going wrong?

OpenStudy (anonymous):

I keep getting " not defined" error messages

OpenStudy (anonymous):

Think I'm getting confused at the raw_input part because I assigned a variable to it but it doesn't seem to work with output

OpenStudy (anonymous):

If you program is: a = "Enter your last name" b = "Enter your first name" print a, b You will get the following output. Enter your last name Enter your first name You are missing the raw_input statement

OpenStudy (anonymous):

Yeah, that's what I'm trying to figure out, is the raw input. I've tried assigning variables but I can't input without getting definition errors

OpenStudy (anonymous):

Here's a hint. This program asks the user to provide their last name and then prints the result. print "Please what is your last name: " last = raw_input() print last See if that works. Then modify it so that then you ask for the first name and then print out both.

OpenStudy (anonymous):

I think I have this? I did a = raw_input ('Enter your last name') b = raw_input ('Enter your first name) it asks for both and when I type print b, a it spits out the first name, then last

OpenStudy (anonymous):

Does that sound right?

OpenStudy (anonymous):

Altogether looks like this: a = raw_input ('Enter your last name') Enter your last name (I enter last) b = raw_input ('Enter your first name') Enter your first name (I enter first) print b, a first last

OpenStudy (anonymous):

a=raw_input() there shouldn't be anything between the parentheses

OpenStudy (anonymous):

Oh. OK. Well then, let me see here.

OpenStudy (anonymous):

Now I'm confused.

OpenStudy (anonymous):

This is what I did. It works. It says there is an error, but it runs fine and it gives the correct output. http://codepad.org/82nKSwai

OpenStudy (anonymous):

Sorry, that one was wrong. http://codepad.org/VMAy1Zh0

OpenStudy (anonymous):

Does this make sense. I know that it isn't in the exact format as your assignment, but I wanted to leave you room for style.

OpenStudy (anonymous):

Ha ok glad to hear it was wrong because it wasn't working for me. I'll check the other one.

OpenStudy (anonymous):

It will let me do the last name, but not first. I get a definition error when I try to enter first name.

OpenStudy (anonymous):

brcourtade, when you are stuck you should first try to solve a simpler problem. can you write a program that asks the user to provide their last name and then prints that back? the program would have three steps. step 1: ask the user to provide the last name (hint: use a print statement); step 2: accept the input the user provides and assign it to a variable (hint: this is where you use the raw_input command). step 3: give the user back the result (hint: use the print statement again. You should be able to write this simpler program with three lines of code

OpenStudy (anonymous):

hm..

OpenStudy (anonymous):

OK, I did that.

OpenStudy (anonymous):

OK! I think I got this. I have print ("Enter your last name") last = raw_input() print ("Enter your first name") first = raw_input() print first, last It looked like it worked does this sound right?

OpenStudy (anonymous):

Yes, you are on the right track

OpenStudy (anonymous):

Word.

OpenStudy (anonymous):

So, did I do something wrong? Something I need to do differently?

OpenStudy (anonymous):

Use codepad or something to allow us to see your code.

OpenStudy (anonymous):

Hmmm yeah codepad says syntax error

OpenStudy (anonymous):

Let's take a look at your code...

OpenStudy (anonymous):

Yeah, post that shiz!

OpenStudy (anonymous):

http://codepad.org/Yg0fuFkj

OpenStudy (anonymous):

Yeah it doesn't work like it worked in IDLE

OpenStudy (anonymous):

So I've done something wrong here.

OpenStudy (anonymous):

Your code is correct. Not sure why it's not working in codepad. But the program works in IDLE and python interpreter.

OpenStudy (anonymous):

Woo!

OpenStudy (anonymous):

Wow I feel like an idiot. Haha can't believe it took me that long to figure out something so simple.

OpenStudy (anonymous):

don't feel like an idiot. the way you learn programming is by making lots of mistakes. the more mistakes you make the better you will get. the key is to be persistent and not give up. great job!

OpenStudy (anonymous):

Thanks for the encouragement. I appreciate that. It felt really good to finally do it right! Still, you have to admit it was a pretty simple problem. Then again, knowing myself, I know I'm always slow in the beginning and if this turns out like most of my learning expeditions I will get exponentially better as I go along. Here'es hoping!

OpenStudy (anonymous):

This is the weirdest subject, it takes a kind of mental strain that is unlike most things I have done. I have done a lot of quantitative stuff, but nothing like this. Just wait till you beat the problem set one. It's super gratifying.

OpenStudy (anonymous):

Well I'll let you know when I get there. Haha

OpenStudy (anonymous):

it doesn't work in codepad because you can't have inputs there

OpenStudy (anonymous):

hello

OpenStudy (anonymous):

Actually, you can have things within the parentheses for raw input. The code you posted was correct, somebody just gave you the wrong idea. It really just depends on your preference.

OpenStudy (anonymous):

yeah you could do raw_input("Enter your name\n") \n is for new line

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!