Input error for Python 3.3.1

This is the place for queries that don't fit in any of the other categories.

Input error for Python 3.3.1

Postby NotAnotherNeo » Sun May 12, 2013 4:21 am

Hey guys, I need help understanding how the hell my input function keeps on failing...

Here's the code:


# This program says hello and asks for my name.
print('Hello world!')
print('What is your name?')
myName = input(Not_another_Neo)
print('It is good to meet you, ' + myName)

This is the error:

Hello world!
What is your name?

Traceback (most recent call last):
File "C:/Python33/awdawd.py", line 5, in <module>
myName = input(Not_another_Neo)
NameError: name 'Not_another_Neo' is not defined


I'm running verion:

Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 20:25:12) [MSC v.1600 32 bit (Intel)] on win32

The tutorial I'm going along with mentions a problem like this would appear if I download the WRONG version... but I downloaded the most updated version... so...

what the hell?


Please be helpful with your answers; not to be a dick or anything, but we're all aware of the ego-strokers. 8-)
NotAnotherNeo
 
Posts: 5
Joined: Sun May 12, 2013 4:04 am

Re: Input error for Python 3.3.1

Postby micseydel » Sun May 12, 2013 4:40 am

NotAnotherNeo wrote:Please be helpful with your answers; not to be a dick or anything

Do you really think that wills stop the dicks? Or just make the good people annoyed? As a tip for helping you in the future, when you're talking to someone new, even on the internet, you should make a habit of speaking to them as if you're in an interview, until you know otherwise is appropriate.

As for your problem, you would get the same error in the situation you mentioned, but here, it's happening because you're trying to use a variable name that doesn't exist. Not_another_Neo doesn't exist. That function takes as input a string that you want the user to be prompted with. Here's what I think you want.

Code:
Code: Select all
print('Hello world!')
myName = input('What is your name?')
print('It is good to meet you, ' + myName)


Session:
Code: Select all
Hello world!
What is your name?Not_another_Neo
It is good to meet you, Not_another_Neo

You could change the input line to
Code: Select all
myName = input('What is your name?\n')

Will get input closer to what it looks like what you wanted.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1267
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Input error for Python 3.3.1

Postby NotAnotherNeo » Sun May 12, 2013 5:14 am

This code:

print('Hello world!')
myName = input('What is your name?')
print('It is good to meet you, ' + myName)


does not become

Hello world!
What is your name?Not_another_Neo
It is good to meet you, Not_another_Neo

also... on a side note...

I tried entering the IRC chatroom, but it requires registration -and I've no idea where to register.

Thanks for the help, *stroke stroke*.
NotAnotherNeo
 
Posts: 5
Joined: Sun May 12, 2013 4:04 am

Re: Input error for Python 3.3.1

Postby micseydel » Sun May 12, 2013 5:23 am

Do you know Linux command line at all?
Code: Select all
$ cat testit.py
print('Hello world!')
myName = input('What is your name?')
print('It is good to meet you, ' + myName)
$ python3 testit.py
Hello world!
What is your name?Michael
It is good to meet you, Michael

cat in this context outputs a file. Then I ran the program, getting that session. I input "Michael" because it asked my name, and then it had output based on my input.

Here's a session that separates the I/O better
Code: Select all
$ python3 testit.py > becomes
Michael
$ cat becomes
Hello world!
What is your name?It is good to meet you, Michael

What this says is "run python3 on the file testit.py and put the output in a file called 'becomes'". The prompt isn't printed to the screen, but instead to a file, although I respond to it, and then I output the file contents which don't include my input, but do include the output based on my input.

Here's a Python 2 session
Code: Select all
$ python2 testit.py
Hello world!
What is your name?Michael
Traceback (most recent call last):
  File "testit.py", line 2, in <module>
    myName = input('What is your name?')
  File "<string>", line 1, in <module>
NameError: name 'Michael' is not defined

Note that the NameError hear happens with respect to the user input (I typed in "Michael") and not having anything to do with the code.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1267
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Input error for Python 3.3.1

Postby NotAnotherNeo » Sun May 12, 2013 5:57 am

I didn't realize that the input function was really just waiting for me to input something... hence the name...


wow...

that tutorial confused me... grrrr wasted like 3 hours trying to find an answer...

Thanks for your help... you actually provided more information than was neccesary.

Oh btw, I made that little spiel to lure somebody competent.

I don't need admonition.
NotAnotherNeo
 
Posts: 5
Joined: Sun May 12, 2013 4:04 am

Re: Input error for Python 3.3.1

Postby metulburr » Sun May 12, 2013 1:19 pm

please use code tags next time
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1416
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Input error for Python 3.3.1

Postby Kebap » Mon May 13, 2013 9:45 am

NotAnotherNeo wrote:I tried entering the IRC chatroom, but it requires registration -and I've no idea where to register.

You don't need to register. Just choose a name and off you go! *stroke* *stroke* :o
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 390
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: Input error for Python 3.3.1

Postby NotAnotherNeo » Mon May 13, 2013 11:41 am

Keep the strokes goin'~ roundNround :D
NotAnotherNeo
 
Posts: 5
Joined: Sun May 12, 2013 4:04 am


Return to General Coding Help

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 3 guests