Build your first reusable Python programs with variables. We store values once, reuse their names, calculate totals, and avoid the common reassignment surprise where old output does not change.
#python #learnpython #pythonbeginners #codingtutorial #programmingbasics
⏱ Chapters:
0:00 Intro — Arohas Code Lab
0:03 One Recipe Amount, Many Steps
0:22 A Label Finds a Stored Value
0:37 Store a Name, Then Read It
0:57 Prices and Counts Become Reusable
1:15 Changing a Variable Affects Future Reads
1:32 Store Changing Facts, Reuse Labels
Challenge
Create a function that receives an item price and a quantity, then returns the total cost.
Entry point:
```python
def total_cost(price, quantity):
return price * quantity
```
Expected behavior:
`total_cost(5, 3)` returns `15`
`total_cost(8, 2)` returns `16`
Worked solution:
```python
def total_cost(price, quantity):
total = price * quantity # Multiply the two input values
return total # Send the calculated result back to the caller
print(total_cost(5, 3)) # Expected output: 15
print(total_cost(8, 2)) # Expected output: 16
```
Explanation: the price and quantity are changing facts, so the function reads their names and calculates the result without hard-coding one shopping trip.
Auf dieser Seite können Sie das Online-Video Python Variables Explained - Store Data in Code mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Arohas Code Lab 20 Mai 2026 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 4 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!