☰ Contents · Computing

Review test and arithmetic operations

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

Test: algorithms and Python basics

Textbook: p. 62
GoalReviews the topics covered so far on algorithms, flowcharts, variables and data types, and solves a task in words and in Python code.
New words
algorithm: a precise sequence of steps that leads from the given data to the result · algoritmflowchart: a picture of an algorithm made of shapes joined by arrows · blok-sxemavariable: a named cell that holds a value · o‘zgaruvchidata type: int, float, str or bool · ma’lumot turi
Explanation

Before the test we put what has been covered in order. An algorithm is a precise sequence of steps that leads to a result; it can be given in words, as a flowchart or as a program. In a flowchart the start and end are shown by an oval, input and output by a parallelogram, a calculation by a rectangle and a condition by a rhombus. In a program data is kept in a variable, its type (int, float, str, bool) is found from the value, and remember that input() always returns a string. First write how the task is solved in words and then turn it into code: this way there are fewer mistakes. At the end, work out the result by hand and compare it with the answer of the program.

Worked examples
Area and perimeter of a square, in words: 1) enter the side a; 2) calculate S = a * a and P = 4 * a; 3) print S and P; 4) stop. In code: a = int(input()) ⏎ print(a * a, 4 * a) If 7 is typed, 49 28 is printed.
Sign of a number, in words: 1) enter x; 2) if x > 0, print “positive”; 3) otherwise, if x < 0, print “negative”; 4) in any other case print “zero”. A condition is checked twice here, so the flowchart has two rhombuses.
Class activity

“Chart – code – result”: pairs choose a small task (circumference, area of a square), write it in words, as a flowchart and in code, and the partner checks that all three match.

Practice
1
Write in words an algorithm for the area of a circle of radius r.
2
Find the sum of the multiples of 5 from 20 to 40 (both included).
3
What is the product of all whole numbers from -3 to 6 and why?
4
Which shape shows a condition in a flowchart?