[Tutor] Beginner level: Why doesn't my code work?

Steven D'Aprano steve at pearwood.info
Sun May 19 16:31:59 CEST 2013


On 19/05/13 23:38, Rafael Knuth wrote:

> Thank you, I am using Python 3.3.0

Based on the error you show, I doubt that very much.

> As for the HTML ... I copied the code from the Python Shell - should I post
> code as a screenshot?
> Would that resolve that issue you mentioned?

No. It has nothing to do with the Python shell, it has to do with your email program.

Your email program will probably have an option somewhere to send "Rich Text" or "Styled Text" or "HTML Text". Turn it off. There are many reasons to avoid it, but as far as this mailing list goes, the main one is that it mangles the code you send and makes it harder to answer your questions.



> "Rafael" is the user's in put, and that value is assigned to the variable
> "name".
> I made sure only a string is accepted as input
>
> name = (str(input("What's your name?"))

The call to str() is unnecessary.

In Python 3, this works as you would expect:

# Python 3.3
py> name = input("What's your name? ")
What's your name? Raphael
py> print(name)
Raphael


But when you run it, that's not the result you get. You get this result:

# Python 2.7
py> name = input("What's your name? ")
What's your name? Raphael
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<string>", line 1, in <module>
NameError: name 'Raphael' is not defined


This tells me very strongly that you are actually using Python 2, not Python 3.

Try this: at the very beginning of your file 3_Tufcik.py, put these two lines:

import sys
print(sys.version)


then run the file as you would normally, and see what it prints.



-- 
Steven


More information about the Tutor mailing list