Issue with accepting strings from user using python's input function?

Hi @vasank1958,

that happens because you executed the script using python2.

In order to make the script work, you have to run the code with python3:

python3 fav_movie.py

This already solves the problem, but if you need an explanation, we have it below


The explanation is:

In python2, input works for numbers, but for strings you have to use raw_input.
In python3, however, input can also be used for strings.

So, to solve the problem you could either:

  1. Run your script with python3:

python3 fav_movie.py

  1. Run with python2, but change input by 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.

3 Likes