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
33

Programming simple problems in Python

Textbook: pp. 70–71
GoalKnows the concepts of a linear algorithm and a linear program, solves a simple task in four stages (data, result, algorithm, testing), and matches a flowchart with program code.
New words
linear algorithm: commands carried out one after another in a strict order, with no conditions or repeats · chiziqli algoritmlinear program: a linear algorithm written as a program · chiziqli dasturinput data: the values the program receives to work with · kiruvchi ma’lumotoutput data: the result the program shows · chiquvchi ma’lumot
Explanation

In a linear algorithm all commands are carried out one after another from top to bottom: no condition is checked and nothing is repeated. A simple task is solved in four stages: 1) find the input data, its type and its name; 2) find what the result is and which type it will have; 3) build the algorithm: input, calculation, output; 4) test it with different values. In a flowchart the oval shows the start and the end, the parallelogram input and output, and the rectangle a calculation; each of them matches one or several lines of code. For example the input block matches an input() line, the calculation block an assignment line, and the output block print(). The fourth stage matters most: by trying an example whose answer is known in advance you see that the algorithm works correctly.

BlockLines of code
inputinput()
calculationassignment (v = s / t)
outputprint()
💡 Where will I use this?
In real life

A frame ribbon was needed for a rectangular poster on a classroom wall. A pupil made a worksheet taking width and length: data, result (perimeter), algorithm, test. The four orderly stages kept mistakes few.

Who uses it

Engineers, accountants and programmers solve a simple problem in four stages and check the answer.

Try it today

Write four stages on paper for another small problem, such as the area of a circle: data, result, formula, test.

Worked examples
Python
1s = int(input())
2t = int(input())
3v = s / t
4print(v)
Output
60.0
Speed v = s / t – code above. The input data are s and t, the result is v (a float). With 180 km and 3 hours the program prints 60.0.
Python
1a = int(input())
2n = int(input())
3m = int(input())
4print(m - a * n)
Output
6500
Change – code above. The price of a notebook is 4500, 3 were bought and 20000 so‘m was paid: the change is 20000 − 4500 · 3 = 6500 so‘m.
Class activity

“From chart to code”: the group draws a flowchart on the board for the volume of a cube (oval – parallelogram – rectangle – parallelogram – oval), then writes the matching line of code under each block.

Practice
1
List in order the four stages of solving a simple task.
2
The edge a of a cube is typed and its volume is printed. Write the program (64 when a = 4).
3
What is the area of a trapezoid with bases 6 and 10 and height 5 by (a + b) * h / 2?
4
Why must a finished algorithm be tested with different values?
Story of the Week · The Khwarizmi WayTalking to the shop ownerClose the week: all of this week’s subjects in one storyRead →