wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Пайтон

Total questions: 15

Worksheet time: 7mins

Name
Class
Date
1.

Try/except блоктарының жұмыс механизмі және finally блогының рөлі

a)

Finally блогы тек қате шыққанда ғана орындалады.

b)

Try/except қателерді ұстап өңдейді, finally блогы қате шықса да, шықпаса да міндетті түрде орындалады.

c)

Try блогы тек синтаксистік қателерді ұстайды.

d)

Except блогы әрқашан try-дан бұрын орындалады.

2.

Кодты толықтырыңыз

try: file = open("data.txt") data = file.read() except: ____________ finally: file.__________

a)

• except: print("Error")
• finally: close()

b)

• except: pass; finally: open()

c)

• except: data.close(); finally: print()

d)

• except: file.write(); finally: continue

3.

ЕСЕП: «Сандарды файлға жазып, орташа мәнін есептеу

a)

nums = input("Сандарды енгізіңіз: ").split()

nums = [int(x) for x in nums]

with open("numbers.txt", "w") as f:

for n in nums:

f.write(str(n) + "\n")

with open("numbers.txt", "r") as f:

data = [int(line) for line in f]

avg = sum(data) / len(data)

print("Орташа мән:", avg)

b)

nums = [1, 2, 3]

data = nums

avg = sum(data) / 3

print(avg)

c)

with open("numbers.txt", "w") as f:

f.write("1 2 3")

with open("numbers.txt", "r") as f:

data = [int(f.read())]

print(sum(data)/len(data))

d)

with open("numbers.txt", "w") as f:

f.write("1\n2\n3\n")

with open("numbers.txt", "r") as f:

lines = f.readlines()

print(lines)

4.
  1. Файлды ашу режимдері

a)

Файл ашу режимдері: "r", "w", "a", "x", "b", "r+", әрқайсысы оқу/жазуға әртүрлі мүмкіндік береді.

b)

Файл тек "read" және "write" режимдерінде ғана ашылады.

c)

Режимдер тек бинарлы файлдарға ғана қатысты.

d)

Python файл режимін автоматты таңдайды, қолмен көрсету қажет емес.

5.
  1. КОДТЫ ТОЛЫҚТЫРУ
    with open("log.txt", "___") as f:

    f.________("Start\n")

a)

"r", read

b)

"b", appendline

c)

"a", write

d)

"w", close

6.

ЕСЕП: Ең жиі кездесетін сөз

a)

with open("text.txt", "r") as f:

text = f.read()

print(text)

b)

with open("text.txt", "r") as f:

chars = f.read()

freq = {}

for c in chars:

freq[c] = freq.get(c, 0) + 1

print(max(freq, key=freq.get))

c)

with open("text.txt", "r") as f:

words = f.read().split()

freq = {}

for w in words:

freq[w] = freq.get(w, 0) + 1

most = max(freq, key=freq.get)

print(most)

d)

with open("text.txt", "r") as f:

words = f.read().split()

print(words[0])

7.

ТЕОРИЯ: ООП принциптері

a)

HTML, CSS, JS — ООП принциптері.

b)

Тек инкапсуляция ғана маңызды.

c)

Компиляция, агрегация, интерфейс — негізгі принциптер.

d)

Негізгі принциптер: инкапсуляция, мұрагерлік, полиморфизм.

8.
  1. КОДТЫ ТОЛЫҚТЫРУ


class Bank:

def init(self, balance):

self.__balance = _______

a)

0

b)

"balance"

c)

self.balance

d)

balance

9.

ЕСЕП: Employee
кате еместы тап

a)

class Employee:

def init(self, name, age, salary):

self.name = name

print("Done")

b)

def raise_salary(amount):

pass

c)

rich = [e.name for e in employees if e.salary < 200000]

d)

class Employee:

def init(self, name, age, salary):

self.name = name

self.age = age

self.salary = salary

def raise_salary(self, amount):

self.salary += amount

employees = [

Employee("Ali", 30, 150000),

Employee("Dana", 25, 250000),

Employee("Nurlan", 40, 300000)

]

rich = [e.name for e in employees if e.salary > 200000]

print(rich)

10.

ТЕОРИЯ: Полиморфизм, инкапсуляция, мұрагерлендіру

a)

Бұл Python кітапханалары

b)

Полиморфизм тек Java-да бар.

c)

Полиморфизм – әдістердің әртүрлі жүзеге асуы; инкапсуляция – деректерді жасыру; мұрагерлендіру – атрибуттарды беру.

d)

Инкапсуляция деректерді көбейтеді.

11.
  1. КОДТЫ ТОЛЫҚТЫРУ
    class Shape:

    def area(self):

    ________

a)

raise NotImplementedError

b)

print("area")

c)

return 0

d)

pass

12.

ЕСЕП: Каталогтағы файлдар

a)

print(".")

b)

import os

path = "."

files = os.listdir(path)

for f in files:

print(f)

with open("data.txt", "r") as f:

for i, line in enumerate(f):

if i % 10 == 0:

print(line.strip())

c)

os.system("ls")

d)

for f in os.listdir("."):

os.remove(f)

13.

ТЕОРИЯ: super()

a)

super() атрибуттарды өшіреді.

b)

super() тек C++ тілінде бар.

c)

super() тек статикалық әдістерге арналған.

d)

super() базалық класстың әдістерін шақыруға мүмкіндік береді.

14.

КОДТЫ ТОЛЫҚТЫРУ
class Student(Person):

def init(self, name, gpa):

super().__________(name)

self.gpa = gpa

a)

run

b)

super

c)

parent

d)

init

15.

ЕСЕП: Teacher фильтр

a)

class Teacher(Person):

def init(self, name, subject, exp):

self.name = name

b)

class Teacher:

def init(self, name):

self.name = name

c)

[t.name for t in teachers if t.subject != "Math"]

d)

class Person:

def init(self, name):

self.name = name

class Teacher(Person):

def init(self, name, subject, exp):

super().__init__(name)

self.subject = subject

self.exp = exp

teachers = [

Teacher("Ali", "Math", 5),

Teacher("Dana", "Physics", 3),

Teacher("Sara", "Math", 4)

]

math_teachers = [t.name for t in teachers if t.subject == "Math"]

print(math_teachers)