December 2017
Beginner
412 pages
10h 8m
English
In Chapter 3, Designing and Using Functions, we explored some built-in functions. Another built-in function is input, which reads a single line of text from the keyboard. It returns whatever the user enters as a string, even if it looks like a number:
| | >>> species = input() |
| | Homo sapiens |
| | >>> species |
| | 'Homo sapiens' |
| | >>> population = input() |
| | 6973738433 |
| | >>> population |
| | '6973738433' |
| | >>> type(population) |
| | <class 'str'> |
The second and sixth lines of that example, Homo sapiens and 6973738433, were typed by us in response to the calls on function input.
If you are expecting the user to enter a number, you must use int or float to get an integer or a floating-point ...
Read now
Unlock full access