-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'sobolevn:main' into new_branch_5
- Loading branch information
Showing
17 changed files
with
990 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Flake8 Lint | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
run-linters: | ||
name: Run linters | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install wemake-python-styleguide | ||
- name: Get changed files | ||
id: changed-files | ||
uses: tj-actions/changed-files@v14.6 | ||
|
||
- name: Lint all python changed files | ||
run: | | ||
FILES=$(echo ${{ steps.changed-files.outputs.all_changed_files }} | grep -P '([-\w\.]+\/)*[-\w\.]+\.py' -o | sed -e 's/^/.\//') | ||
[ -z "$FILES" ] && echo No python files to check || (echo Checking files: $FILES ... && echo $FILES | xargs flake8 --count --statistics) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Empty files checking | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
custom_test: | ||
runs-on: ubuntu-latest | ||
name: Check empty files | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Checking | ||
run: | | ||
if find . -type f -empty | sed '/__init__.py/d' | grep ".*"; then | ||
echo Empty files above 🥹 ^^ | ||
exit 1 | ||
else | ||
echo Success! | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class Array(object): | ||
|
||
def __init__(self, *args): | ||
self._data = args | ||
|
||
def __len__(self): | ||
return len(self._data) | ||
|
||
def __str__(self): | ||
return str(self._data) | ||
|
||
def __getitem__(self, ind): | ||
return self._data[ind] | ||
|
||
def __iter__(self): | ||
return iter(self._data) | ||
|
||
def __add__(self, other): | ||
res = Array() | ||
res._data = self._data + other._data | ||
return res | ||
|
||
def append(self, arg): | ||
self._data = self._data + (arg,) | ||
|
||
def index(self, obj): | ||
if obj in self._data: | ||
return( self._data.index(obj) ) | ||
return -1 | ||
|
||
def main(): | ||
mas_a = Array(1,2) | ||
print(f'first array = {mas_a}' ) | ||
mas_b = Array(3,4,5,6) | ||
print(f'second array = {mas_b}' ) | ||
mas_a.append(33) | ||
print(f'first array after append(33) = {mas_a}') | ||
mas_sum = mas_a + mas_b | ||
print(f'array of sum first and second: {mas_sum}') | ||
print(f'length of sum array is {len(mas_sum)}') | ||
print(f'index of element 1 in sum array is {mas_sum.index(1)}') | ||
|
||
for el in mas_sum: #array working with for loop | ||
print(el) | ||
|
||
print(f'Sum array el number [1] is {mas_sum[1]}') | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Класс списков | ||
|
||
class Array(object): | ||
def __init__(self, *args): | ||
self._data = args | ||
|
||
def append(self, item): | ||
self._data += (item,) | ||
|
||
def __add__(self, other): | ||
result = Array() | ||
result._data = self._data + other._data | ||
return result | ||
|
||
def __len__(self): | ||
return len(self._data) | ||
|
||
def index(self, item): | ||
if item in self._data: | ||
return self._data.index(item) | ||
else: | ||
return -1 | ||
|
||
def __iter__(self): | ||
return iter(self._data) | ||
|
||
def __getitem__(self, index): | ||
return self._data[index] | ||
|
||
def __str__(self): | ||
return str(self._data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import random | ||
|
||
secrets = {"Какая версия языка сейчас актуальна?":"Python3", "Какая кодировка используется в строках?":"UTF8","Какой оператор сравнения нужно использовать для работы с None и bool?":"is", "Сколько значений есть у bool?":"2" } | ||
|
||
num_ques = 10 | ||
num_right_ans = 0 | ||
|
||
print("\nДавайте сыграем в игру загадки! Итак начнём!\n") | ||
|
||
for i in range(num_ques): | ||
ki = random.choice(tuple(secrets.keys())) | ||
print(f"\tВопрос №{i+1}") | ||
print(ki) | ||
ans = input('Введите свой ответ: ') | ||
if secrets[ki].lower() == ans.lower(): | ||
print(f"\nОтвет {ans} верен") | ||
num_right_ans += 1 | ||
else: | ||
print("\nНеверный ответ") | ||
|
||
print(f"\nИгра закончилась!\n\tВаша статистика:\nВсего ответов - {num_ques}\nВерных ответов - {num_right_ans}\nНеверных ответов - {num_ques - num_right_ans}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
class Array(object): | ||
|
||
# Конструктор (инициализирует данные) | ||
def __init__(self, *args): | ||
self._data = tuple(args) | ||
# print(type(self._data)) | ||
|
||
# Печатает элементы array | ||
def printdata(self): | ||
for item in self._data: | ||
print(f"Элемент массива = {item}") | ||
print() | ||
|
||
# Добавляет элемент к array | ||
def append(self, arg): | ||
self._data = self._data + (arg,) | ||
|
||
# складывает элементы array (складываем 2 tuple и распаковываем его с помощью *) | ||
def __add__(self, array): | ||
return Array(*(self._data + array._data)) | ||
|
||
# функция, которая выдаёт длину array | ||
def __len__(self): | ||
return len(self._data) | ||
|
||
# Определяет index элемента в array | ||
# Как будто есть ещё какой-то вариант | ||
def index(self, elem): | ||
if elem in self._data: | ||
return self._data.index(elem) | ||
return -1 | ||
|
||
# позволяет получить значение array с помощью [] | ||
def __getitem__ (self, index): | ||
return self._data[index] | ||
|
||
# Позволяет делать итерацию в цикле for по array | ||
def __iter__(self): | ||
return iter(self._data) | ||
|
||
# 1) Создавать себя как на примере: `Array()` - пустой списо, | ||
# `Array(1)` = список из одного объекта `1`, `Array(1, 2, 3)` | ||
# список из трех объектов. `Array` должен уметь работать с любым количеством аргументов | ||
|
||
print("\nТест № 1\n") | ||
a = Array() | ||
b = Array(1) | ||
c = Array(1, 'c', "Hello", (2,3,4), 0.2) | ||
|
||
# 2) Добавлять новый объект внутрь списка через метод `.append()` | ||
|
||
print("\nТест № 2\n") | ||
b.printdata() | ||
b.append('Hello') | ||
b.printdata() | ||
|
||
# 3) Складываться с другими `Array`. Например: `Array(1) + Array(2) == Array(1, 2)` | ||
|
||
print("\nТест № 3\n") | ||
d = b + c | ||
d.printdata() | ||
|
||
# 4) Узнавать свою длину через функцию `len()` | ||
|
||
print("\nТест № 4\n") | ||
print(f"Длина Array d = {len(d)}") | ||
|
||
# 5) находить индекс переданного объекта через метод `.index()`, возвращаем `-1`, | ||
# если такого объекта в списке нет. Например: `Array('a', 'b').index('b') == 1` | ||
|
||
print("\nТест № 5\n") | ||
print(d.index(1)) | ||
print(d.index("c")) | ||
print(d.index(2)) | ||
|
||
# 6) Работать с циклом `for`: `for element in Array(1, 2, 3):` | ||
|
||
print("\nТест № 6\n") | ||
for elem in d: | ||
print(elem) | ||
|
||
# 7) Получать значение по индексу при помощи `[]`. Пример: `Array('a')[0] == 'a'` | ||
|
||
print("\nТест № 7\n") | ||
print(d[0]) | ||
print(d[3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
score = 0 | ||
|
||
questions = [ | ||
'Какая версия языка сейчас актуальна?', | ||
'Какая кодировка используется в строках?', | ||
'Какой оператор сравнения нужно использовать для работы с None и bool?', | ||
'Сколько значений есть у bool?', | ||
'Python - низкоуровневый язык?', | ||
'Python объектно-ориентированный язык?', | ||
'Какая типизация реализована в Python?', | ||
'В каком году появился Python?', | ||
'На каком языке написан интерпретатор CPython?', | ||
'Сколько планет в Солнечной системе?' | ||
] | ||
|
||
answers = [ | ||
'Python3', | ||
'UTF-8', | ||
'is', | ||
'2', | ||
'Нет', | ||
'Да', | ||
'Динамическая', | ||
'1991', | ||
'C', | ||
'8' | ||
] | ||
|
||
for i in range(len(questions)): | ||
print(questions[i], end='\n') | ||
user_ans = input() | ||
if user_ans.lower() == answers[i].lower(): | ||
print('Ответ {0} верен.'.format(user_ans), end='\n') | ||
score += 1 | ||
else: | ||
print('Неверный ответ.', end='\n') | ||
|
||
|
||
print('Ваш общий балл: {0}/10.'.format(score)) |
Oops, something went wrong.