Page 1 of 1 [ 4 posts ] 

Rudin
Veteran
Veteran

User avatar

Joined: 7 Jun 2015
Age: 21
Posts: 1,046
Location: Southern Ontario

01 Dec 2015, 6:32 pm

I have decided to learn how to program this week. Currently I am enjoying it.

I have made a extremely basic program using what I learned about inputs and outputs, it is a bit crude.

Code:
person = input ('Enter your name: ')
print ('I hate the name', person)


I saved it as program.py and in the terminal I used the command python program.py. I got a strange error,

Enter your name: C
Traceback (most recent call last):
File "hello_you.py", line 1, in <module>
person = input('Enter your name: ')
File "<string>", line 1, in <module>
NameError: name 'C' is not defined

What did I do wrong? I do I fix this?


_________________
"God may not play dice with the universe, but something strange is going on with prime numbers."

-Paul Erdos

"There are two types of cryptography in this world: cryptography that will stop your kid sister from looking at your files, and cryptography that will stop major governments from reading your files."

-Bruce Schneider


Last edited by Rudin on 01 Dec 2015, 6:39 pm, edited 2 times in total.

Earthling
Veteran
Veteran

User avatar

Joined: 23 Aug 2015
Posts: 3,450

01 Dec 2015, 6:35 pm

Code:
[code]Your code here[/code]

Makes code much more accessible to the eye.
I don't know Python, sorry. :(



Freedoomed
Veteran
Veteran

User avatar

Joined: 17 Oct 2015
Age: 28
Gender: Male
Posts: 960

01 Dec 2015, 9:25 pm

That most certainly is because you are compiling Python 3 code with Python 2.
The right way to compile it is python3 program.py.

If you want to compile it with Python 2, you should do the following:

person = raw_input ('Enter your name: ')
print 'I hate the name', person



Rudin
Veteran
Veteran

User avatar

Joined: 7 Jun 2015
Age: 21
Posts: 1,046
Location: Southern Ontario

02 Dec 2015, 6:44 pm

Freedoomed wrote:
That most certainly is because you are compiling Python 3 code with Python 2.
The right way to compile it is python3 program.py.

If you want to compile it with Python 2, you should do the following:

person = raw_input ('Enter your name: ')
print 'I hate the name', person


This fixed it, thank you.


_________________
"God may not play dice with the universe, but something strange is going on with prime numbers."

-Paul Erdos

"There are two types of cryptography in this world: cryptography that will stop your kid sister from looking at your files, and cryptography that will stop major governments from reading your files."

-Bruce Schneider