AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Contents · Computing

Practical tasks and linear programs

Lessons 32–33 · 2 lessons · M. R. Fayziyeva, D. M. Sayfurov, N. S. Xaytullayeva. Informatics and Information Technologies, Grade 9. “Nashriyot uyi Tasvir”, Tashkent, 2020
32

Practical lesson: input and output

Textbook: pp. 69–70
GoalIn the practical lesson, programs tasks on dividing quantities equally and splitting them into units with // and %, and reads values from one line with split().
New words
equal sharing: // gives each share, % gives what is left over · teng taqsimlashremainder: the part that does not make a whole share · qoldiqarithmetic mean: the sum of the numbers divided by how many there are · o‘rta arifmetiksplit(): cuts a typed line into parts · split()
Explanation

Most tasks of this lesson are alike: an amount is shared into equal portions and the question is what is left over. Here // gives each portion or the number of whole groups, and % gives the leftover part. In a money example we find the number of the biggest banknotes with //, and then repeat the same thing for the remaining sum with smaller banknotes. If several numbers are typed in one line, input().split() separates them, and then each part must be converted with int(). To find the arithmetic mean of several numbers, put the sum in brackets and divide by how many numbers there are. Always test the program on 2–3 examples worked out by hand, especially in the case where the remainder is zero.

💡 Where will I use this?
In real life

Organisers of a school evening needed to seat 130 guests in rows of 12. Division with remainder gave 10 full rows and 10 guests left over, so they planned one more short row.

Who uses it

Storekeepers, organisers and programmers split items into equal portions and account for the remainder.

Try it today

On paper, change 200 minutes into hours and minutes using whole quotient and remainder, then check by adding back.

Worked examples
Python
1n = int(input())
2a = n // 50000
3r = n % 50000
4b = r // 10000
5c = r % 10000
6print(a, b, c)
Output
3 3 7000
Splitting money into banknotes – code above. If 187000 so‘m is typed, the result is 3 notes of 50000, 3 notes of 10000 and 7000 left (3 3 7000).
Python
1a = input().split()
2k = int(a[0])
3m = int(a[1])
4print(k // m, k % m)
Output
4 5
Putting pencils into boxes – code above. With 53 pencils and 12 per box, there are 4 full boxes and 5 pencils left (4 5).
Class activity

“Shop cashier”: a pair chooses the price of an item and the money paid; it writes a program giving the change in the largest banknotes (// and %), and the partner checks it by hand.

Practice
1
How many full 50000 so‘m notes are in 187000 so‘m?
2
We pack 53 pencils 12 per box. How many boxes are needed to hold all of them?
3
Write a program that prints the arithmetic mean of three numbers typed with spaces.
4
Why is % used to find the leftover amount?
Story of the Week · The Khwarizmi WayTalking to the shop ownerClose the week: all of this week’s subjects in one storyRead →