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

I'm having trouble, I'm trying to write a program that asks user to enter their last name then first and it keeps saying syntax error?

OpenStudy (anonymous):

what have you got so far?

OpenStudy (anonymous):

well i was starting with print "Enter your last name" answer = raw_input () is this right so far?

OpenStudy (anonymous):

Well, the raw input function takes a "prompt" argument, meaning that a better way to do that would be answer = raw_input('Enter your last name: ') What raw input does is it prints a prompt (whatever you put in quotes inside the parentheses) and returns the user's input after the prompt. So you can think of answer = raw_input('Enter your last name: ') as meaning: answer = what the user types after the prompt 'Enter your last name: ' But when I ran what you just posted: print "Enter your last name" answer = raw_input () I did NOT get a syntax error. Is there anything else in the file you were running that might've caused one? can you post the error message?

OpenStudy (anonymous):

Enter your last name Traceback (most recent call last): File "C:/Python31/homework2.py", line 2, in <module> answer = raw_input () NameError: name 'raw_input' is not defined >>>

OpenStudy (anonymous):

but i get it now it needs something written to define what raw_input is.

OpenStudy (anonymous):

Thank You Very MUCH!

OpenStudy (anonymous):

That error message is a Strange Thing. I'm pretty sure raw_input should always be defined. I'm not sure what's going on there.

OpenStudy (anonymous):

If it persists, maybe try typing that line in the shell: answer = raw_input('Enter your last name: ') and just see what happens. I don't know if that will work and I have no particular reason to think it'll fix anything, but it's something I sometimes try as a sanity check to make sure I'm using a function correctly.

OpenStudy (anonymous):

Enter your last name Traceback (most recent call last): File "C:/Python31/Homework1.py", line 2, in <module> answer = raw_input("Enter your last name") NameError: name 'raw_input' is not defined >>>

OpenStudy (anonymous):

It did it again.

OpenStudy (anonymous):

Any Ideas?

OpenStudy (anonymous):

I'd try creating a new document first. Then, if that didn't work, I'd type answer = raw_input('Enter your last name: ') directly in the shell, just to see if that worked. If it didn't, I'd try closing IDLE and restarting it. I'm also curious what happens when you type help('__builtin__') in the shell. raw_input is in the built in module--that module is supposed to be included in everything. If it's not getting included, I'm not at all sure why.

OpenStudy (anonymous):

It did the same thing when i opened a new doc

OpenStudy (anonymous):

What about when you type it in the shell?

OpenStudy (anonymous):

The same thing happens when i type it into shell. When I type the help('__builtin__') it says no documentation was found under python?

OpenStudy (anonymous):

no python documentation was found.

OpenStudy (anonymous):

very weird. you've tried restarting IDLE?

OpenStudy (anonymous):

yes and i had the same problem.

OpenStudy (anonymous):

Gears, you're using Python 3. The course materials are written for Python 2. You'll have quite a few issues; I suggest you google on what those issues might be. I only know about the print statement; I've been careful to avoid Python 3 until a nice, sunny day on the beach. :)

OpenStudy (anonymous):

Thank you so much I was not the person who installed the program this was my partner. This should fix many issues thank you.

OpenStudy (anonymous):

Thanks Radly. I was becoming pretty confused.

OpenStudy (anonymous):

Gears, you're using Python 3. The course materials are written for Python 2. You'll have quite a few issues; I suggest you google on what those issues might be. I only know about the print statement; I've been careful to avoid Python 3 until a nice, sunny day on the beach. :)

OpenStudy (anonymous):

The path in the error trace gave it away. Luckily, he happened to be using a path that captured that clue. Otherwise, I'd have had no idea either.

OpenStudy (anonymous):

Oh yeah! Error messages have become some of my main tools for debugging, but I didn't think to look at the path. The stuff I need is usually after that part. lesson learned.

OpenStudy (chris):

hi Radly, don't want you to lose your reply if you've started. Server will be restarting in one minute! see you after the jump. Gears - sorry for polluting your question. Thanks

OpenStudy (anonymous):

I'm also using python 3, trying to stay hip with the times. So far the two big differences I've run into are that print is now a function so you should use parentheses [ex.print("enter your name")] and "raw_input" is now just "input". Try it out! For a more complete list of the differences between python 2.x and 3 check out this page. http://docs.python.org/release/3.1.2/whatsnew/3.0.html

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!
Latest Questions
Lilmunchin: Trump or Biden
10 minutes ago 66 Replies 2 Medals
ARTSMART: Art!
1 hour ago 5 Replies 5 Medals
Jasonisyours: What were the key causes of the French Revolution in 1789?
1 hour ago 3 Replies 5 Medals
PureSoulless: Why is the word "Pedophile" always censored in yt vids?
1 day ago 3 Replies 0 Medals
Jalli: What's 58x3634u00b07
23 hours ago 6 Replies 3 Medals
arriya: who wanna play roblox
1 day ago 5 Replies 1 Medal
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!