Python Tutorial / Build a First Program with Variables, Input and Output
Python variables refer to values, input() reads text and print() displays results. Convert input text to a numeric type before using it in arithmetic, then format the result for the reader.
Distinguish assignment from comments
The assignment operator = associates the result on its right with the name on its left. It does not test mathematical equality. Reassigning a name makes later expressions use the new value. Choose meaningful names and avoid overwriting built-in names such as print, input or list.
amount = 3500 amount = amount + 500 print(amount) # Display the calculated result
This prints 4000. Text after # is a comment rather than an executed instruction. Comments are most useful when they explain a choice, unit or constraint instead of merely restating the code.
For the relevant APIs and platform requirements, see Build a First Program with Variables, Input and Output documentation.
Run the input and output example
Save the following as input_expense.py and run python input_expense.py in the project environment. Enter lunch at the name prompt and 8000 at the amount prompt.
name = input("name: ").strip()
amount_text = input("amount: ").strip()
amount = int(amount_text)
print(f"{name}: {amount:,} KRW")
The program’s standard output, with the typed input omitted, is:
name: amount: lunch: 8,000 KRW
Follow each value through conversion
The first call reads an expense name and removes surrounding whitespace. amount_text remains a string until int() converts it to an integer. An f-string places expressions inside braces; the comma format specifier displays thousands separators.
A terminal normally echoes what you type, so its interactive line layout will differ from the output-only block above. Input waiting is also normal: a stationary cursor does not necessarily mean the program is stuck.
Change one input and inspect failures
- Enter 9000 instead of 8000 and check for 9,000 KRW.
- Enter 8000.5 and observe ValueError because int() does not parse a decimal-point string.
- Try an empty amount, then restore the valid 8000 input and confirm normal execution.
Track where text becomes a number rather than assuming that a numeric-looking input is already numeric. Handling invalid input and asking again requires a deliberate validation loop; the exception handling lesson explains how to add that behavior without hiding unrelated failures.






