Easy_506 Posted February 24, 2014 Posted February 24, 2014 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!
mikecampbell Posted February 24, 2014 Posted February 24, 2014 (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 February 24, 2014 by mikecampbell
Easy_506 Posted February 24, 2014 Author Posted February 24, 2014 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...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now