it accepts numbers without error, however when i input text it says the “text” is not defined.
In order to avoid problems like this, please:
- put the following on the first line of your python file, to indicate it’s a python executable:
#! /usr/bin/env python
- Enclose your string inputs within quotes:
"sfa"instead of just
Please let us know how it goes.
By the way, welcome to the community!
that happens because you executed the script using python2.
In order to make the script work, you have to run the code with python3:
This already solves the problem, but if you need an explanation, we have it below
The explanation is:
input works for numbers, but for
strings you have to use
In python3, however,
input can also be used for strings.
So, to solve the problem you could either:
- Run your script with python3:
- Run with python2, but change
raw_input. In this case, the code would be:
movie = raw_input ('What is your favorite movie? ')
and you could execute it normally with python2, but giving that the course is about python3, I’d suggest you the first option.