Skip to content
Open

Jar #129

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dk92_spasky/Lab3/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Перелік змін:
1) Видалено зайві коментарі.
2) Було створено окрему функцію для переводу імен.
3) Додано docstring для кожної із функцій.
4) Змінено назви змінних, для кращого розуміння.
93 changes: 93 additions & 0 deletions dk92_spasky/Lab3/rand_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python3

import itertools
import random
from functools import partial
from math import ceil
from pathlib import Path
from transliterate import translit
from yaml import safe_load


LANG='uk'

def translator(value):
'''Translates the group name and student names into English.'''

return translit(value, language_code=LANG, reversed=True)


def parse_students(filename, lang=LANG):
'''
Opens a yaml file, and writes the group and student names translated
into English as a dictionary.
'''
with open(filename) as f:
dictionary = safe_load(f)
dictionary = {translator(key): [(translator(v).replace(' ', '_'), v)
for v in values]
for key, values in dictionary.items()}
return dictionary


def read_questions(directory):
'''
The function reads the questions from the given file, sorts them
and writes them to a variable of dictionary type.
'''
pth = Path(directory)
dictionary = {}
for file in sorted(list(pth.glob('*.*'))):
with open(file) as f:
qst = f.read().strip().split('\n#')
qst[1:] = ['#' + q for q in qst[1:]]
dictionary[file.name] = qst

return dictionary


def generate_questions(students, questions, *, numeach=2):
'''
The function is designed to generate an individual task for each student.
'''
sep = '=' * 30 + '\n'
files = dict()
for group, lst in students.items():
for tr, orig in lst:
files[f'{group}_{tr}.rst'] = f'{sep}{orig}\n{sep}\n'

for catname, category in questions.items():
print(f'{catname:<40}', end='\t')
personal = list(itertools.combinations(category, numeach))
print(f'{len(personal)} combinations')
assert len(personal) >= len(files)
random.shuffle(personal)
for f in files:
files[f] += '\n' + '\n'.join(personal.pop(0)) + '\n'

return files


def write_files(outdir, files):
'''
The function creates a file separately for each student,
and this file records previously generated individual questions.
'''
odir = Path(outdir)
odir.mkdir(exist_ok=True)
for filename, contents in files.items():
file = odir.joinpath(filename)
with open(file, 'x') as f:
f.write(contents)


if __name__ == '__main__':
from sys import argv
if len(argv) != 4:
print(f'Usage\n{argv[0]} student_list questions_dir out_dir')
exit(-1)
student_list, questions_dir, out_dir = argv[1:]
students = parse_students(student_list)
qst = read_questions(questions_dir)
cont = generate_questions(students, qst, numeach=2)
write_files(out_dir, cont)
68 changes: 68 additions & 0 deletions dk92_spasky/MKR/Mkr2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import random
from array import *


class Cube_defolt():
cube_edges = 6

def __init__(self, edges=cube_edges, is_relollable=False):
self.edges = edges
self.is_relollable = is_relollable
self.value_of_cube = 0


def roll(self):
if self.is_relollable == True or self.value_of_cube == 0:
self.value_of_cube = random.randint(1, self.edges)
return print (f'{self.value_of_cube}')

def __str__(self):
if self.value_of_cube == 0:
return 'The cube was not thrown'
else:
return 'Value of cube is ',self.value_of_cube


def __ne__(self, other):
if self.value_of_cube != other.value_of_cube and self.value_of_cube != 0 and other.value_of_cube != 0:
return 'The values ​​of the cubes not equivalent'
else:
return 'The condition is not met'


def __eq__(self, other):
if self.value_of_cube != 0 and other.value_of_cube != 0 and self.value_of_cube == other.value_of_cube:
return 'The values ​​of the cubes are equivalent'
else:
return 'The condition is not met'



def __lt__(self, other):
if self.value_of_cube != 0 and other.value_of_cube != 0 and self.value_of_cube < other.value_of_cube :
return f'{self.value_of_cube} < {other.value_of_cube}'
else:
return 'The condition is not met'


@classmethod
def handout(cls, X: int, Y: int):
players_list = []
for a in range(X * Y):
players_list.append(Cube_defolt().roll())
return players_list


class Cube_15(Cube_defolt):
cube_edges = 15


class Cube_11(Cube_defolt):
cube_edges = 11


if __name__ == '__main__':
cbm = Cube_defolt()
cbm.roll()


17 changes: 17 additions & 0 deletions dk92_spasky/lab2/README.RST
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Мета роботи: створити декілька класів, реалізувати наслідування

Проект має:
Батьківський Клас "energy"
Дочірні класи:
"hydro_power_plant" - параметри: name, year, power, water_flow.
"windmill"- параметри: name, year, power, wind_speed.
"thermal_power_plant" - параметри: name, year, power, coal_cnsmp.

Реалізований --str-- метод для вивода повної інформації про станцію.

Для перевірки було викликано функції які входять до того чи іншого класу.
Для прикладу:
1) Отримати значення потужності однієї із станцій
2) Отримати значення унікальної змінної одного із дочірніх класів
3) Змінити значення змінної яка встановлена раніше
4) Вивести повну інформації про один із створених класів
168 changes: 168 additions & 0 deletions dk92_spasky/lab2/lab2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import os

os.system('clear')


class energy:
''' class energy.
parameters:

name
year
power
water_flow
wind_speed
coal_cnsmp
'''

name = ''
year = 0
power = 0
water_flow = 0
wind_speed = 0
coal_cnsmp = 0


def __init__(self, name='NONE', year=0,
water_flow=0, wind_speed=0, coal_cnsmp=0):
''' energy constructor'''
self.name = name
self.year = year
self.power = power
self.water_flow = water_flow
self.wind_speed = wind_speed
self.coal_cnsmp = coal_cnsmp

def get_name(self):
'''method prints name of station.
Else prints unknown name
'''
if(self.name != 'NONE\n'):
print('Name of station: ',self.name)
else:
print('NO NAME\n')

def get_year(self):
'''method prints
year of foundation'''
if (self.year != 0):
print('Name of station: ', self.name, 'founded:', self.year, '\n')

def get_power(self):
'''method prints power of station'''
if (self.name != 'NONE \n'):
print('Name of station: ', self.name, 'power :', self.power, '\n')

def __str__(self):
powerstat = 'Name of station: ' + str(self.name) + "\n" + \
'founded: ' + str(self.year) + '\n'

if(self.__class__.__name__ == 'hydro_power_plant'):
powerstat = powerstat + 'water_flow: ' + \
str(self.water_flow) + ' m^3/s\n'
if(self.__class__.__name__ == 'windmill'):
powerstat = powerstat + 'wind_speed: ' + \
str(self.wind_speed) + ' m/s \n'
if(self.__class__.__name__ == 'thermal_power_plant'):
powerstat = powerstat + 'coal_cnsmp: ' + \
str(self.coal_cnsmp) + 't/m\n'
powerstat = powerstat + 'power: ' + str(self.power) + ' megWATT \n'

return powerstat


class hydro_power_plant(energy):
'''class hydro_power_plant .
parameters:

name
year
power
water_flow
'''

def __init__(self, name='NONE', year=0, power=0, water_flow=0 ):
'''hydro_power_plant class constructor'''
self.name = name
self.year = year
self.power = power
self.water_flow = water_flow

def get_water_flow(self):
''' the method returns
the value water_flow'''
print(self.name, ' water flow = ', self.water_flow, ' m^3/s\n')

def set_water_flow(self, new_water_flow):
''' the method sets
the value water_flow '''
self.water_flow = new_water_flow
print(self.name, 'New water_flow:', self.water_flow, ' m^3/s\n')


class windmill(energy):
''' class windmill .
parameters:

name
year
power
wind_speed
'''

def __init__(self, name='NONE', year=0, power=0,
wind_speed=0):
'''windmill class constructor'''

self.name = name
self.year = year
self.power = power
self.wind_speed = wind_speed

def get_wind_speed (self):
'''the method returns
the value wind_speed '''
print(self.name, ' wind speed = ', self.wind_speed, '\n')


class thermal_power_plant(energy):
'''thermal_power_plant class.
parameters:
name
year
power
coal_cnsmp
'''

def __init__(self, name='NONE', year=0, power=0, coal_cnsmp=0 ):
'''thermal_power_plant class constructor'''
self.name = name
self.year = year
self.power = power
self.coal_cnsmp = coal_cnsmp


def get_coal_cnsmp (self):
'''the method returns
the value coal_cnsmp'''
print(self.name, ' coal is used :', self.coal_cnsmp, '\n')


if(__name__ == '__main__'):
TPP_1 = thermal_power_plant('ZTPP', 1973, 3650, 90)
windmill_1 = windmill('pyriatin windmill', 2020, 80, 25)
HPP_1 = hydro_power_plant('DTPP', 1932, 838, 300 )

TPP_1.get_power()
windmill_1.get_wind_speed()
HPP_1.get_water_flow()
windmill_1.get_name()
HPP_1.set_water_flow(46)
HPP_1.get_water_flow()

print(HPP_1)
print(TPP_1)
print(windmill_1)