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

Simple task practice and logical expressions

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

Practical lesson: simple problems

Textbook: p. 72
GoalIn the practical lesson, programs simple tasks by the four stages: chooses the variables, writes the formula and tests the result.
New words
formula: a rule written with variables, for example S = PI * r ** 2 · formulaconstant PI: written in capital letters; here PI = 3.14 · doimiy PItest: a run with a known answer to check the program · sinovtype of the result: int or float, depending on the task · natija turi
Explanation

In this lesson we work independently: first write each task in four stages in the notebook (input data, result, calculation, test), and only then write code. In geometry tasks write the formula correctly once and declare PI once as a constant. The area of a ring is the area of the big circle minus the area of the small one: PI * (R ** 2 - r ** 2); if the brackets are forgotten the answer is different. The sum of the numbers from 1 to n can be found without a loop by the formula n * (n + 1) // 2. If the program gives a wrong answer, check the formula first and then the variable names; a misspelled variable name gives a NameError. In all tasks make it a habit to check the answer by hand.

ƒFormula
PI * (R ** 2 - r ** 2)
ring area = big circle area – small circle area
💡 Where will I use this?
In real life

A class wanted to cover a wall display board with paper. A pupil worked in four stages: the board’s width and height were the data, the area was the result, the formula was width times height, and the answer was tested against a rough estimate.

Who uses it

Builders, gardeners and programmers use measurements to calculate and check a needed quantity.

Try it today

Take the width and length of your room or classroom. Find the area on paper with a formula and a calculation.

Worked examples
Python
1n = int(input())
2print(n * (n + 1) // 2)
Output
5050
The sum from 1 to n – code above. If 100 is typed, 5050 is printed; to check by hand take n = 4: 1 + 2 + 3 + 4 = 10.
Python
1PI = 3.14
2a = input().split()
3R = int(a[0])
4r = int(a[1])
5print(PI * (R ** 2 - r ** 2))
Output
50.24
Area of a ring – code above. With R = 5 and r = 3 the area is 3.14 · (25 − 9) = 50.24.
Class activity

“Formula workshop”: the group writes on cards the formulas for the area of three shapes (a circle, a ring, a right triangle) in Python notation; a partner gives values and calculates by hand and by program.

Practice
1
7350 g of flour was brought to the kitchen. Write it in kilograms and grams (using // and %).
2
The air temperature on three days was 18, 21 and 24 degrees. Find the average temperature.
3
Each truck carries 30 sacks. How many trucks are needed to carry 250 sacks?
4
Why must R ** 2 - r ** 2 be put in brackets in the area of a ring?
Story of the Week · The Khwarizmi WayWhat a simple agreement must sayClose the week: all of this week’s subjects in one storyRead →