Jump to content

Recommended Posts

Posted

Hi all,

 

Hopefully someone out there will be able to point me in the right direction on this... Disclaimer: I know nothing about Python.

 

Initial proposal was to set up VMs running Python, but instead we've opted to use the Codecademy Labs online. Not a problem for most stuff, until one of our ICT teachers reported the code below:

 

firstname = input("Please enter your first name: ")

surname = input("Please enter your last name: ")

county = input("Please enter your county: ")

print("Hello {0} {1}. You live in the county of: {2}.".format(firstname,surname,county))

 

 

This works fine when run from an installed Python GUI. So when I run, it prompts me to enter my firstname, surname etc. And you can see what it spits out in the last line of code.

 

But when trying to run on the Codecademy website it returns the following:

 

Traceback (most recent call last):

File "", line 1, in

File "", line 1, in

NameError: name 'Matt' is not defined

 

 

Anyone got any ideas on this? Many thanks in advance!

Posted (edited)

I'm not a regular python coder but I think it may be to do with differences in the version of python.

 

As I understand it in Python 2.x you need to use raw_input() to capture a string, because input() will capture then eval the input as Python code (I'm assuming this behaviour changed at some point if you're saying it works for you locally). So essentially what you were doing equates to:

 

firstname = Matt

 

and obviously there's no such object `Matt`!

Edited by mikecampbell
Posted

Thanks for your reply. Makes some sense since the Web Lab runs v.2.7 and the download I installed this morning was 3.something.

 

If anyone else out there has any other thoughts i'm all ears! Google searched this particular error earlier and got more results than humanly possible to sift through...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...