5.1 The input function
Another very useful function is input: it takes a string that it prints on the screen (the user’s prompt), and returns a string with what the user typed on the keyboard until they pressed the RETURN or ENTER key. Run the code below and type in your name, followed by RETURN or ENTER.
Note that input always returns a string, even if the user typed in a number. To see the implications of that, run the code below and type in your birth year.
The computer reports a type error, because the code is mixing two different types of data. It is trying to subtract the string returned by input from the number 2015.
OpenLearn - Simple coding
Except for third party materials and otherwise, this content is made available under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 Licence, full copyright detail can be found in the acknowledgements section. Please see full copyright statement for details.
