Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Python: getting user input error

input error exit user input

  • Please log in to reply
2 replies to this topic

#1 Alcamech

Alcamech

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 181 posts
  • Location:In the pursuit of happiness
  • Programming Language:Python
  • Learning:C, Java, C++, C#, Python, JavaScript

Posted 20 July 2012 - 07:33 PM

Code:

#Personal Greeter
#Demonstrates the getting user input

name = input("Hi. Whats your name? ")

print(name)

print("Hi,", name)

input("\n\nPress the enter key to exit.")

When I run this program in command prompt and go to input my name it gives an error and closes . what do i have to do to fix this error

Error :

Traceback (most recent call last):
File "E:\Programming\Programming files\Python Programming\Personal Greeter(ch.2).py", line 6, in <module>
name = input()
File "<string>", line 1, in <module>
NameError: name 'lawton' is not defined


Edited by Roger, 06 August 2012 - 03:59 PM.
added code tags

  • 0

#2 Microsuck

Microsuck

    CC Regular

  • Member
  • PipPipPip
  • 35 posts
  • Location:127.0.0.1
  • Programming Language:PHP
  • Learning:C, Java, C++, Objective-C, C#, PHP, Python, JavaScript, Perl, Bash, Others

Posted 21 July 2012 - 05:51 PM

You need to use raw_input() instead of input() in Python 3.

name = raw_input("Hi. Whats your name? ")

print(name)

print("Hi,", name)

raw_input("\n\nPress the enter key to exit.")

  • 0

#3 WaterNode

WaterNode

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 69 posts
  • Location:Seattle, WA, United States of America
  • Programming Language:C, Java, C++, C#, Python
  • Learning:C, Java, C++, C#, Python, Lua, Assembly, Others

Posted 29 August 2012 - 03:55 PM

Really? I use Python 3x.
Just do it this way:
print('Hi, what is your name?')
name = input()
print('Hi,' + name)
print('Press enter to exit.')
input()

  • 0





Also tagged with one or more of these keywords: input, error, exit, user input

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download