The Student Room Group

Python help

Hey guys, I keep getting an error message on my program but I am not sure why. My task was to create a sign up program for a club and it should ask the user for their first name, surname, gender and form and the details should be stored as a text file
help.JPG
Reply 1
I don't know python, but it appears that your input function doesn't respond to non-string inputs. Either write "John" with the quotation marks when asked for a firstname, or change all the 'input' functions to 'raw_input' functions and then be able to write John without quotation marks. The 'raw_input' function will be able to intetpret non-string inputs and treat them as if they were string inputs.

Hope that helps :smile:
(edited 6 years ago)
Reply 2
I agree with what Maivnek said, using quotes should help.

I think in Python 2.7 (which it looks like you're using), there was another function called raw_input(), which you can use instead of the input() function and that should allow you to type the name in without any quotes. In a later version of Python (version 3 onwards I believe), raw_input() was replaced with input() and so your script would have worked fine in that version.

On a side note, your line: "details = ['firstname','surname','gender','form']" might not have the desired effect, you may need to remove the single quotes to print the actual values to the file.
The two posts above have already pointed out the issue with input vs raw_input - there's a good explanation of the problem here:

https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined
Original post by Maivnek
I don't know python, but it appears that your input function doesn't respond to non-string inputs. Either write "John" with the quotation marks when asked for a firstname, or change all the 'input' functions to 'raw_input' functions and then be able to write John without quotation marks. The 'raw_input' function will be able to intetpret non-string inputs and treat them as if they were string inputs.

Hope that helps :smile:


Original post by TheMatt
I agree with what Maivnek said, using quotes should help.

I think in Python 2.7 (which it looks like you're using), there was another function called raw_input(), which you can use instead of the input() function and that should allow you to type the name in without any quotes. In a later version of Python (version 3 onwards I believe), raw_input() was replaced with input() and so your script would have worked fine in that version.

On a side note, your line: "details = ['firstname','surname','gender','form']" might not have the desired effect, you may need to remove the single quotes to print the actual values to the file.


Original post by winterscoming
The two posts above have already pointed out the issue with input vs raw_input - there's a good explanation of the problem here:

https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined


Thank you all for your help I'll give that a go

Quick Reply

Latest

Trending

Trending