Lessons 1–5 · About 60 min per lesson
Input, variables and calculations
Read keyboard input, store it in variables and calculate a result.
Lesson breakdown
- Lesson 1
Run a first program, change what print says and run it again.
- Lesson 2
Store stock and demand in variables and observe what changes after assignment.
- Lesson 3
Read a line with input and turn numeric text into an integer with int.
- Lesson 4
Compute totals, full bags and remainders with +, -, *, // and %, and check operator order.
- Lesson 5
Print numbers in the required format and distinguish a conversion error from a wrong result.
Worked example
Each bag holds 5 kg. Given 17 kg, print the number of full bags and the kilograms left over.
How to solve it
17 // 5 gives 3 bags and 17 % 5 leaves 2 kg. Convert the input text to an integer before calculating.
total = int(input())
print(total // 5, total % 5)Assignment
Read two positive integers, total kilograms and bag capacity, then print the number of full bags and the remainder.
Check your result
20, 5 → 4 0; 3, 5 → 0 3; 17, 5 → 3 2.