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

Loop practice and a review test

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

Test: Python basics

Textbook: p. 86
GoalReviews the Python basics covered – variables, data types, arithmetic, strings, if…else and for – and solves mixed tasks.
New words
variable and type: a name with a value of type int, float, str or bool · o‘zgaruvchi va turoperation and expression: + - * / // % ** with brackets and the order of operations · amal va ifodacondition: a bool expression that if or elif checks · shartloop: for repeats the body a known number of times · sikl
Explanation

Before the test recall the main rules. A variable name starts with a letter or an underscore, is not a keyword, and capital and small letters differ. input() returns a string: if a number is needed, int() or float() is written. // and % are for whole division and the remainder; the last digit of a number is x % 10 and the tens digit is x // 10 % 10. In conditions do not forget the difference between == (comparison) and = (assignment); and/or/not make compound conditions; after if and else come a colon and an indent of 4 spaces. In the loop for i in range(a, b), b is not included; a sum starts from 0 and a product from 1. If you see an error, read the message from the end and find the line number. Always check the answer by hand on a small example.

💡 Where will I use this?
In real life

Before a test a pupil summarised all topics on one sheet and listed personal mistakes. During revision the pupil gave more time to the topics with the most mistakes.

Who uses it

Students, people preparing for professional exams and programmers write down their mistakes and focus revision on them.

Try it today

Write the mistakes from your last three exercises on paper and explain in one sentence why each happened.

Worked examples
Python
1x = int(input())
2print(x // 100 % 10)
3
4ism = input()
5print("Omad,", ism, end="!")
Output
8
Omad, Aziz!
Separating a digit – the first program above. If 4825 is typed, the hundreds digit 8 is printed. Setting the output – the second program above. If Aziz is typed, Omad, Aziz! is printed (the exclamation mark at the end comes from end).
Python
1x = 5
2if x = 5:
3    print(x)
Output
SyntaxError
A mistake to find – code above: SyntaxError: the condition needs ==, while = is assignment. The correct line is if x == 5: (with a colon at the end).
Class activity

“Mini test”: pairs write 4 short tasks in each other’s notebook (variable, type, if, for) and hide the answers; the partner solves them and then they check together.

Practice
1
A book has 360 pages. If 25 pages are read every day, in how many days is the book finished (even if the last day has fewer pages)?
2
Write a program that finds the hundreds digit of a positive whole number (8 for 4825).
3
What does for i in range(3): print(i * i, end=" ") print?
4
Why is the line if x = 5: wrong?
Story of the Week · The Khwarizmi WayThe trial review: do we go on?Close the week: all of this week’s subjects in one storyRead →