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?
what have you got so far?
well i was starting with print "Enter your last name" answer = raw_input () is this right so far?
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?
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 >>>
but i get it now it needs something written to define what raw_input is.
Thank You Very MUCH!
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.
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.
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 >>>
It did it again.
Any Ideas?
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.
It did the same thing when i opened a new doc
What about when you type it in the shell?
The same thing happens when i type it into shell. When I type the help('__builtin__') it says no documentation was found under python?
no python documentation was found.
very weird. you've tried restarting IDLE?
yes and i had the same problem.
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. :)
Thank you so much I was not the person who installed the program this was my partner. This should fix many issues thank you.
Thanks Radly. I was becoming pretty confused.
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. :)
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.
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.
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
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
Join our real-time social learning platform and learn together with your friends!