input() displays a prompt and returns whatever the user enters as a string. Use the prompt to collect data, then convert that string when the program needs a number or another type. section 1.2 section 1.3
A practical input workflow is:
- Display a clear prompt, such as input('Enter your name: '). section 1.2
- Convert numeric input explicitly: int() for integers or float() for floating-point values. section 1.3 section 1.13
- Handle invalid numeric responses with try and except ValueError. section 1.13
- Remember that pressing Enter returns an empty string, which behaves as False in a conditional. section 1.13
Validated numeric input
try: n = float(input('Enter a number: ')) print(f'n = {n}') except ValueError: print("That's not a valid number!") section 1.13
name = input('Enter your name: ')
print(f'Hello, {name}!')
A minimal prompt-and-response pattern combines input() with an f-string. section 1.2






