3  User input

Warning

Any changes you make to the code on this page, including your solutions to exercises, are temporary. If you leave or reload the page, all changes will be lost. If you would like to keep your work, copy and paste your code into a separate file or editor where it can be saved permanently.

3.1 Asking user for input

To ask the user for input, we can use the built-in input function:

Run the code in the cell above several times and enter different names.

Note that the input function always returns a string (even if the user enters a number), but we can use type conversion functions such as int and float to convert the given string to other types:

If the user enters something else than (just) an integer, the conversion will fail with a ValueError. Try it!