A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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?

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    what have you got so far?

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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?

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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 >>>

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thank You Very MUCH!

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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 >>>

  10. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It did it again.

  11. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Any Ideas?

  12. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  13. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    It did the same thing when i opened a new doc

  14. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    What about when you type it in the shell?

  15. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  16. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    no python documentation was found.

  17. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    very weird. you've tried restarting IDLE?

  18. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    yes and i had the same problem.

  19. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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. :)

  20. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

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

  21. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks Radly. I was becoming pretty confused.

  22. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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. :)

  23. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  24. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  25. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  26. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  27. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.