From eca0f86f19d700620303b9ed88ccdf6534bbfe91 Mon Sep 17 00:00:00 2001 From: Marina Postnikova Date: Sun, 26 Jul 2020 17:34:05 +0300 Subject: [PATCH 1/9] Tasks compare 2 lists and pizza are ready --- compare_lists.py | 14 ++++++++++ pizza.py | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 compare_lists.py create mode 100644 pizza.py diff --git a/compare_lists.py b/compare_lists.py new file mode 100644 index 0000000..3357a5a --- /dev/null +++ b/compare_lists.py @@ -0,0 +1,14 @@ +list1 = [1, 1.0, "3"] +list2 = [1, 1.0, "3"] + + +def compare_2_lists(list_1, list_2): + if not isinstance(list_1, (list, tuple)): + return False + if type(list_1) == type(list_2) and len(list_1) == len(list_2): + for index in range(len(list_1)): + if list_1[index] != list_2[index]: + return False + return True + else: + return False diff --git a/pizza.py b/pizza.py new file mode 100644 index 0000000..98729f8 --- /dev/null +++ b/pizza.py @@ -0,0 +1,71 @@ +class Pizza: + ingredients = [] + name = "" + + def get_name(self): + return self.name + + def prepare_dough(self): + print("The dough is ready!") + + def add_ingredients(self): + pass + + + def bake_pizza(self): + print("The pizza is baking!") + + + def cook(self): + self.prepare_dough() + self.add_ingredients() + self.bake_pizza() + print(self.get_name() + " is ready!") + + +class MushroomPizza(Pizza): + ingredients = ["mushrooms", "onion", "cheese"] + name = "Mushroom pizza" + + def add_ingredients(self): + for ingredient in self.ingredients: + print(ingredient + " is added!") + + +class MeatPizza(Pizza): + ingredients = ["sausage", "bacon", "ham", "olives", "tomato", "cheese"] + name = "Meat pizza" + + def add_ingredients(self): + for ingredient in self.ingredients: + print(ingredient + " is added!") + + + +class VegetablesPizza(Pizza): + ingredients = ["olives", "tomato", "onion", "pickled cucumber", "paprika", "potato", "cheese"] + name = "Vegetables pizza" + + def add_ingredients(self): + for ingredient in self.ingredients: + print(ingredient + " is added!") + + +while True: + print("Please chose mushroomPizza or meatPizza or vegetablesPizza and enter the name.") + pizzaName = input(); + if (not pizzaName): + break + else: + if (pizzaName == "mushroomPizza"): + mushroomPizza = MushroomPizza() + mushroomPizza.cook() + elif (pizzaName == "meatPizza"): + meatPizza = MeatPizza() + meatPizza.cook() + elif (pizzaName == "vegetablesPizza"): + vegetablesPizza = VegetablesPizza() + vegetablesPizza.cook() + else: + print("Such pizza isn`t exist, please try again!") + From d6a4db54d38496710bd1652f9dfa6065ab5147de Mon Sep 17 00:00:00 2001 From: Marina Postnikova Date: Fri, 31 Jul 2020 22:28:34 +0300 Subject: [PATCH 2/9] Practice task from 31.07.2020 --- practice.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 practice.py diff --git a/practice.py b/practice.py new file mode 100644 index 0000000..559aedc --- /dev/null +++ b/practice.py @@ -0,0 +1,28 @@ +a = [10, 27, 42, 36] + +def max_value(a): + max_val = 0; + for i in range(0, len(a)): + if a[i] > max_val: + max_val = a[i] + + print(max_val) + return max_val + + +max_value(a) + + +arr_value = [10, 20, 30, 40] +arr_index = [] +arr_with_tuples = [] +def enumerate(arr_value): + for index in range(0, len(arr_value)): + b = (index, arr_value[index]) + arr_with_tuples.append(b) + #arr_with_tuples = [(arr_index, arr_value) for index in arr_index for value in arr_value ] + print(arr_with_tuples) + return arr_with_tuples + + +enumerate(arr_value) From 37496156d421a7c2e1b6d5db5cdfe7a10a931bd2 Mon Sep 17 00:00:00 2001 From: Marina Postnikova Date: Sun, 2 Aug 2020 10:33:09 +0300 Subject: [PATCH 3/9] Practice #4 --- practice_4.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 practice_4.py diff --git a/practice_4.py b/practice_4.py new file mode 100644 index 0000000..4b77bb9 --- /dev/null +++ b/practice_4.py @@ -0,0 +1,69 @@ +def analyze_numbers_and_print_FizzBuzz(): + for i in range(0, 101): + if i % 3 == 0: + print("Fizz") + if i % 5 == 0: + print("Buzz") + if i % 15 == 0: + print(i) + print("FizzBuzz") + + +analyze_numbers_and_print_FizzBuzz() + + +def read_number_and_print_digit_by_digit(number): + if len(number) != 5: + print("The number must includes 5 digits! Please, try again!") + return + for index, item in enumerate(number): + print("{} цифра равна {}".format(index+1, item)) + print("And from the end to the beginning!") + for index, item in enumerate(number[::-1]): + print("{} цифра равна {}".format(index+1, item)) + + +read_number_and_print_digit_by_digit("12345") +read_number_and_print_digit_by_digit("123") + + +def sorting_by_choice(array): + for i in range(len(array)): + for j in range(0, len(array) - i - 1): + if array[j] > array[j + 1]: + array[j], array[j+1] = array[j+1], array[j] + print(array) + + +array1 = [100, 2222222, 85, 789, 1, 1258, 1478952, 15, 58, 1, 65, 69, 78, 52, 2563, 1, 0, 3, 24, 2, 3, 7] +sorting_by_choice(array1) + + +def change_tab_for_whitespace(file_name, to_spaces=True): + tab = "\t" + whitespaces = " " + with open(file_name, "r+") as file_for_read: + buffer = file_for_read.read() + if to_spaces: + buffer = buffer.replace(tab, whitespaces) + else: + buffer = buffer.replace(whitespaces, tab) + with open("file1.txt", "wt") as file_for_rewrite: + file_for_rewrite.write(buffer) + + +change_tab_for_whitespace("forRead.txt", to_spaces=True) + + +def replace_with_a_template(str, dictionary): + list = str.split(" ") + for word in list: + if word in dictionary: + str = str.replace(word, dictionary[word]) + return str + + +string123 = "Py is one of OOP language. There are 3 principles of OOP wich includes E and I and P." +dictionary1 = {'OOP': 'object oriented programming', 'Py': 'Python', 'E': 'Encapsulation', + 'I': 'Inheritance', 'P.': 'Polymorphism.'} +print(replace_with_a_template(string123, dictionary1)) \ No newline at end of file From 9e8232d213e11eb2727fb01b39390bc9fd447438 Mon Sep 17 00:00:00 2001 From: Marina Postnikova Date: Fri, 7 Aug 2020 22:01:46 +0300 Subject: [PATCH 4/9] The practice_5 is ready --- practice_5.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 practice_5.py diff --git a/practice_5.py b/practice_5.py new file mode 100644 index 0000000..b0d11a5 --- /dev/null +++ b/practice_5.py @@ -0,0 +1,64 @@ +import time +import random +import os + + +class Man: + name = "name" + + def __init__(self, name): + self.name = name + + def get_name(self): + return self.name + + + @classmethod + def solve_task(cls): + print("I`m not ready!") + + +class Pupil(Man): + + @classmethod + def solve_task(cls): + print("Pupil is thinking...") + random_time = random.randint(3, 6) + print(random_time) + time.sleep(random_time) + print("I`m not ready!") + + + +class WrapStrToFile(object): + + def __init__(self, file_path): + self.file_path = file_path + + @property + def content(self): + if (not self.file_path): + print("File doesn`t exist!") + with open(self.file_path, "r+") as file_for_read: + buffer = file_for_read.read() + print(buffer) + + @content.setter + def content(self, value): + with open(self.file_path, "a") as file_for_rewrite: + file_for_rewrite.write(value) + + + @content.deleter + def content(self): + os.remove(self.file_path) + + + +w = WrapStrToFile("Read.txt") +w.content +string = "Python is one of object oriented programming language. There are 3 principles of object oriented programming wich includes " \ + "Encapsulation and Inheritance and Polymorphism." + +w.content = string +del w.content \ No newline at end of file From b094d594eea1b8d2228b811f888651329239a956 Mon Sep 17 00:00:00 2001 From: Marina Postnikova Date: Sun, 16 Aug 2020 20:02:47 +0300 Subject: [PATCH 5/9] \'The tanks\' is ready --- tanks.py | 225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 tanks.py diff --git a/tanks.py b/tanks.py new file mode 100644 index 0000000..a53f135 --- /dev/null +++ b/tanks.py @@ -0,0 +1,225 @@ +import random +import math + +class Game: + TURNS = {'Q': (-1, -1), + 'W': (-1, 0), + 'E': (-1, 1), + 'A': (0, -1), + 'Z': (1, -1), + 'X': (1, 0), + 'D': (0, 1), + 'C': (1, 1)} + + def __init__(self): + self.pf = None + self.tank = None + self.target = None + self.last_direction = self.TURNS['W'] + self._is_game_over = False + + def start(self): + self._start_game() + + def _start_game(self): + while True: + self.pf = PlayingField() + self.pf.create_playing_field() + self.pf.print_playing_field() + if not self._choose_tank(): + print("Game is finished!") + break + self._put_tank() + self._put_target() + self.pf.print_playing_field() + while not self._is_game_over: + self._make_turn() + self._move_target() + + def _choose_tank(self): + print("Please enter 1 to choose 1 type of tank which move for 2 distances and shoot for 1 distances" + "or enter 2 to choose 2 type of tank to which move for 1 distances and shoot for 2 distances." + "If you want to finish, please, press 3") + while True: + type_of_tank = input() + if type_of_tank == '1': + self.tank = Tank(2, 1) + return True + if type_of_tank == '2': + self.tank = Tank(1, 2) + return True + if type_of_tank == '3': + return False + else: + print("Invalid input! Try again!") + + + def _put_tank(self): + x = random.randint(0, self.pf.FIELD_SIZE_HEIGHT - 1) + y = random.randint(0, self.pf.FIELD_SIZE_LENGTH - 1) + self.tank.set_position(x, y) + self.pf.put_game_object(self.tank) + + def _put_target(self): + self.target = Target() + while True: + x = random.randint(0, self.pf.FIELD_SIZE_HEIGHT - 1) + y = random.randint(0, self.pf.FIELD_SIZE_LENGTH - 1) + x1, y1 = self.tank.get_position() + if abs(x - x1) > self.tank.shoot_distance or abs(y - y1) > self.tank.shoot_distance: + self.target.set_position(x, y) + self.pf.put_game_object(self.target) + break + + def _make_turn(self): + is_shoot_allowed = True + print("Please, choose your turn") + print("Allowed actions: for moves: {}, and for shooting: ' '".format(list(self.TURNS.keys()))) + step_count = self.tank.step_distance + while step_count > 0 and not self._is_game_over: + while True: + choice = input() + choice = choice.upper() + print("Choice '{}', is_shoot_allowed = {}".format(choice, is_shoot_allowed)) + if choice == " " and is_shoot_allowed: + step_count = 0 + self._make_shoot() + break + if choice not in self.TURNS: + print("Invalid input! Try again!") + continue + turn = self.TURNS[choice] + if self.pf.is_move_allowed(self.tank, turn): + self.pf.move_game_object(self.tank, turn) + self.last_direction = turn + self.pf.print_playing_field() + is_shoot_allowed = False + break + else: + print("Such turn isn`t allowed!") + step_count -= 1 + + def _move_target(self): + while True and not self._is_game_over: + direction = random.choice(list(self.TURNS)) + if self.pf.is_move_allowed(self.target, self.TURNS[direction]): + self.pf.move_game_object(self.target, self.TURNS[direction]) + break + self.pf.print_playing_field() + + def _make_shoot(self): + shell_position = self.pf.get_new_position(self.tank, self.last_direction) + shell = Shell() + shell.set_position(shell_position[0], shell_position[1]) + shoot_distance = self.tank.shoot_distance + + while shoot_distance: + if self.target.get_position() == shell.get_position(): + shell.symbol = 'X' + self.pf.put_game_object(shell) + self._is_game_over = True + print("YOU HAVE WON!") + return + elif self.pf.is_move_allowed(shell, (0, 0)): + self.pf.put_game_object(shell) + self.pf.print_playing_field() + else: + return + self.pf.remove_game_object(shell) + shoot_distance -= 1 + if shoot_distance != 0: + new_x, new_y = self.pf.get_new_position(shell, self.last_direction) + shell.set_position(new_x, new_y) + + self.pf.print_playing_field() + print("Miss! Distance is {:.2f}".format(shell.get_distance(self.target))) + + +class PlayingField: + FIELD_SIZE_HEIGHT = 10 + FIELD_SIZE_LENGTH = 10 + EMPTY_CELL = " " + + def __init__(self): + self.playing_field = [] + + def create_playing_field(self): + for index in range(self.FIELD_SIZE_HEIGHT): + field_length = [] + for index1 in range(self.FIELD_SIZE_LENGTH): + field_length.append(self.EMPTY_CELL) + self.playing_field.append(field_length) + + def print_playing_field(self): + print("#" * (self.FIELD_SIZE_LENGTH + 2)) + for row in self.playing_field: + line = "".join(row) + print(f"#{line}#") + + print("#" * (self.FIELD_SIZE_LENGTH + 2)) + + def put_game_object(self, game_object): + x, y = game_object.get_position() + self.playing_field[x][y] = game_object.symbol + + def remove_game_object(self, game_object): + x, y = game_object.get_position() + self.playing_field[x][y] = self.EMPTY_CELL + + def get_new_position(self, game_object, turn): + x, y = game_object.get_position() + to_x, to_y = turn + return x + to_x, y + to_y + + def is_move_allowed(self, game_object, turn): + new_x, new_y = self.get_new_position(game_object, turn) + if new_x < 0 or new_x >= self.FIELD_SIZE_HEIGHT or new_y < 0 or new_y >= self.FIELD_SIZE_LENGTH: + return False + if self.playing_field[new_x][new_y] != self.EMPTY_CELL: + return False + return True + + def move_game_object(self, game_object, turn): + x, y = game_object.get_position() + new_x, new_y = self.get_new_position(game_object, turn) + self.playing_field[x][y] = self.EMPTY_CELL + game_object.set_position(new_x, new_y) + self.playing_field[new_x][new_y] = game_object.symbol + + +class GameObject: + def __init__(self, symbol): + self.symbol = symbol + self.x = 0 + self.y = 0 + + def set_position(self, x, y): + self.x = x + self.y = y + + def get_position(self): + return self.x, self.y + + def get_distance(self, game_object): + return math.sqrt(math.pow(self.x - game_object.x, 2) + math.pow(self.y - game_object.y, 2)) + + +class Tank(GameObject): + def __init__(self, step_distance, shoot_distance): + super(Tank, self).__init__('T') + self.step_distance = step_distance + self.shoot_distance = shoot_distance + + +class Target(GameObject): + def __init__(self): + super(Target, self).__init__('@') + + +class Shell(GameObject): + def __init__(self): + super(Shell, self).__init__('.') + + +g = Game() +g.start() From da28823564f72a8aa0ef1c8aa1341f9cd8303481 Mon Sep 17 00:00:00 2001 From: MarinaSpasskova Date: Mon, 17 Aug 2020 20:44:44 +0300 Subject: [PATCH 6/9] Practice_6 is ready --- practice_6.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 practice_6.py diff --git a/practice_6.py b/practice_6.py new file mode 100644 index 0000000..c23ba3a --- /dev/null +++ b/practice_6.py @@ -0,0 +1,59 @@ +import datetime +import time +import itertools + +def chargen(): + for c in '0123456789': + yield c + + +words = [c + c for c in chargen()][:10] +print(words) + + +def multiplier(m, source=[1, 2, 3]): + return [m * i for i in source] + + +print(multiplier(2, [2, 4, 8])) + + +class MyContextManager: + def __enter__(self): + print("Start time: {}".format(datetime.datetime.now().time())) + self.start_time = time.time() + + def __exit__(self, exc_type, exc_val, exc_tb): + print("Finish time: {}, duration: {:.3f}".format(datetime.datetime.now().time(), time.time() - self.start_time)) + + +with MyContextManager(): + list_1 = [23, 125, 89, 56, 58, 58, 100, 2222222, 85, 789, 1, 1258, 1478952, 15, 58, 3, 24, 2, 3, 7] + time.sleep(1) + list_2 = [i*365 for i in list_1] + print(list_2) + + +def get_3_lists_return_1(list1, list2, list3): + new_list = [] + new_list.extend(list1) + new_list.extend(list2) + new_list.extend(list3) + print(new_list) + return new_list + + +get_3_lists_return_1([1, 2, 3], [4, 5, 6], [7, 8, 9]) + + +def return_words_longer_than_5(the_list): + return [item for item in the_list if len(item) >= 5] + + +print(return_words_longer_than_5(['Hello', 'i', 'write', 'cool', 'code'])) + + +def show_all_combinations(string): + return [i for i in itertools.permutations(string)] + +print(show_all_combinations("password")) From 55671460cc9bbf250cc5c1ff29a4aacf9beb91ed Mon Sep 17 00:00:00 2001 From: MarinaSpasskova Date: Sat, 29 Aug 2020 13:31:40 +0300 Subject: [PATCH 7/9] Exam tasks are ready --- exam_8_lec.py | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 exam_8_lec.py diff --git a/exam_8_lec.py b/exam_8_lec.py new file mode 100644 index 0000000..d48743e --- /dev/null +++ b/exam_8_lec.py @@ -0,0 +1,162 @@ +from itertools import zip_longest + + +# Task 1 +def get_len(the_list): + count = 0 + for i in the_list: + count += 1 + return count + + +li = [1, 2, 3] +print("#Task 1:", get_len(li)) + + +# Task 2 +def my_revrsed(the_list): + i = 0 + j = len(the_list) - 1 + while i < j: + the_list[i], the_list[j] = the_list[j], the_list[i] + i += 1 + j -= 1 + return the_list + + +li_1 = [1, 2, 3, 5, 8, 9] +print("#Task 2:", my_revrsed(li_1)) + + +# Task 3 +def my_range(*args): + start = 0 + step = 1 + if len(args) == 1: + stop = args[0] + elif len(args) == 2: + start = args[0] + stop = args[1] + else: + start = args[0] + stop = args[1] + step = args[2] + i = start + if step < 0: + while i > stop: + yield i + i += step + else: + while i < stop: + yield i + i += step + + +print("#Task 3:", list(my_range(8, 5, -1))) + + +# Task 4 +def to_title(string): + list_1 = string.split(" ") + list_2 = [] + for i in list_1: + if i: + list_2.append(i.replace(i[0], i[0].upper())) + return " ".join(list_2) + + +print("#Task 4:", to_title("python python python")) + + +# Task 5 +def count_symbol(string, symbol): + count = 0 + for i in string: + if symbol == i: + count += 1 + return count + + +print("#Task 5:", count_symbol("python python python", "p")) + +# Extra Task2 +""" +x = [[1, 2, 3, 4]]*3 - создаст 3 элемента листа, которые будут ссылаться на 1 и тот же экземпляр листа [1, 2, 3, 4], +отсюда проблема - при изменении x[0] изменятся также остальные + y = [[1, 2, 3, 4] for _ in range(3)] - создаст 3 разных экземпляра листа, изменения y[0] не повлияет на другие +""" + + +# Extra Task3 +class Counter: + _COUNT = 0 + + def __init__(self): + Counter._COUNT += 1 + + @classmethod + def get_instances_number(cls): + return cls._COUNT + + +c = Counter() +b = Counter() +print("#Extra Task3:", c.get_instances_number()) + + +# Extra Task4 +def make_dict(key_list, value_list): + my_dict = {} + my_zip = zip + if len(key_list) > len(value_list): + my_zip = zip_longest + for key, value in my_zip(key_list, value_list): + my_dict[key] = value + return my_dict + +print("#Extra Task4:",make_dict([1,2,3], ["one", "two", "three"])) +print("#Extra Task4:",make_dict([1,2,3], ["one", "two"])) +print("#Extra Task4:",make_dict([1,2], ["one", "two", "three"])) + + +#Task 9 +class User(): + name = "name" + age = 0 + + def __init__(self, name, age): + self.name = name + + def set_name(self, name): + self.name = name + self.age = age + + + def get_name(self): + return self.name + + def set_age(self, age): + self.age = age + + def get_age(self): + return self.age + +class Woker(User): + salary = 0 + + def __init__(self, name, age, salary): + super(Woker, self).__init__(name, age) + self.salary = salary + + + def set_salary(self, salary): + self.salary = salary + + def get_salary(self): + return self.salary + + +Jonh = Woker('Jonh', 25, 1000) +Jack = Woker('Jack', 26, 2000) +sum_salary = Jonh.get_salary() + Jack.get_salary() +print("Task 9:",sum_salary) From ea615fef1687a82755064d37764f3f514274101a Mon Sep 17 00:00:00 2001 From: MarinaSpasskova Date: Sat, 29 Aug 2020 21:14:42 +0300 Subject: [PATCH 8/9] Practice_7 is ready --- practic_7.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 practic_7.py diff --git a/practic_7.py b/practic_7.py new file mode 100644 index 0000000..3cdc8d0 --- /dev/null +++ b/practic_7.py @@ -0,0 +1,80 @@ +from datetime import datetime, timedelta +from subprocess import Popen, PIPE +import pickle + + +# Task_1 +def calculate_work_days(first_date, second_date): + date_1 = datetime.strptime(first_date, "%d.%m.%Y") + date_2 = datetime.strptime(second_date, "%d.%m.%Y") + period = (date_2 - date_1).days + all_days = 0 + for i in range(period + 1): + day = date_1 + timedelta(i) + print(i, day) + if day.weekday() <= 4: + all_days += 1 + return all_days + + +print(calculate_work_days("24.08.2020", "30.08.2020")) + + +# Task_2 +def read_file(file_name): + print('{}'.format(file_name)) + proc = Popen(['type', '{}'.format(file_name)], shell=True, stdout=PIPE, stderr=PIPE) + proc.wait() + result = proc.communicate() + if proc.returncode: + print(result[1]) + return result[0] + + +print(read_file("f1.txt").decode("utf8")) + + +# Task_3 +class Human: + name = "name" + surname = "surname" + age = 0 + city = "city" + profession = "profession" + + def __init__(self, name, surname, age, city, profession): + self.name = name + self.surname = surname + self.age = age + self.city = city + self.profession = profession + + def __repr__(self): + return f"Human(name='{self.name}', surname='{self.surname}', age='{self.age}', city='{self.city}', profession='{self.profession}')" + + +names = ['Фёдор', 'Василиса', 'Марк', 'Марфа', 'Никодим'] +surnames = ['Казаков', 'Белобокина', 'Шарапов', 'Собакина', 'Худобяк'] +ages = [89, 78, 85, 68, 99] +cities = ['NN', 'SP', 'MSC', 'VLC', 'LIS'] +professions = ['QA', 'Project Manager', 'Team Leader', 'Programmer', 'Senior programmer'] + + +def create_people(number): + with open('human.data', 'wb') as f: + people = [] + for i in range(number): + h = Human(names[i], surnames[i], ages[i], cities[i], professions[i]) + people.append(h) + pickle.dump(people, f) + + +def recover_data(): + with open('human.data', 'rb') as f: + people = pickle.load(f) + for human in people: + print(human) + + +create_people(5) +recover_data() From 1f6982a51074f4805d738c5e647b61eb6b49ece8 Mon Sep 17 00:00:00 2001 From: MarinaSpasskova Date: Sat, 29 Aug 2020 21:18:51 +0300 Subject: [PATCH 9/9] Rename the variable in 1 task --- practic_7.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/practic_7.py b/practic_7.py index 3cdc8d0..1ce17ab 100644 --- a/practic_7.py +++ b/practic_7.py @@ -8,13 +8,13 @@ def calculate_work_days(first_date, second_date): date_1 = datetime.strptime(first_date, "%d.%m.%Y") date_2 = datetime.strptime(second_date, "%d.%m.%Y") period = (date_2 - date_1).days - all_days = 0 + work_days = 0 for i in range(period + 1): day = date_1 + timedelta(i) print(i, day) if day.weekday() <= 4: - all_days += 1 - return all_days + work_days += 1 + return work_days print(calculate_work_days("24.08.2020", "30.08.2020"))