Skip to content

Hw2 bredov #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
Binary file added HW2_Bredov/2023-09-13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions HW2_Bredov/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Script `calculator.py` performs all basic operations: addition, subtraction, multiplication and division.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было бы сделать чуть более подробное описание вашего функционала. Пример использования какой-нибудь. Мало ли кто-то поставит ваш калькулятор себе но будет подавать выражение без пробелов ("2+2"). Но это уже совсем чтобы красоту навести.


Credits:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Круто что вы перечислили обязанности каждого члена команды 👍


* Bobkov Gleb A. - implemented division;
* Bagrova Olga E. - implemented addition;
* Smertina Elena - implemented multiplication;
* Matach Dmitri A. - implemented subtraction;
* Bredov Denis V. - implemented `main()` function & team lead.

![Development crew](./2023-09-13.png "Development crew")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Милота ☺️

25 changes: 25 additions & 0 deletions HW2_Bredov/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def divide(a, b):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь и далее лучше использовать более информативные названия переменных. Названия a и b не отражают содержимого. Лучше было бы, например, num1 и num2. Здесь за это баллы еще не снижаем, но с ДЗ 4 нейминг начнет влиять на оценку.

return a/b
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не хватает пробелов


def add(a,b):
return a+b
Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь и в других местах не хватает оформления пробелами. Всё правильно, но на будущее вот так будет выглядеть чуть лучше:

Suggested change
def add(a,b):
return a+b
def add(a, b):
return a + b


def multiply(x,y):
return(x*y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В таких случаях оформлять return скобками не принято. Так делают обычно если вы возвращаете несколько объектов


def subtract(eq1,eq2):
return(eq1-eq2)
Comment on lines +10 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def subtract(eq1,eq2):
return(eq1-eq2)
def subtract(num1, num2):
return num1 - num2

Что значит eq? 😄 Мы же не уравнения вычитаем


def main():
# eq = [int(i) if i.isdigit() else i for i in input().split()]
Copy link
Member

@nvaulin nvaulin Sep 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обычно закомменченный код не очень хорошо оставлять в репозитории.

eq = input().split()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь было бы супер распаковать eq сразу в 3 элемента:
num1, operator, num2 = input().split()

match eq[1]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Огонь что использовали pattern matching!
Его добавили совсем недавно, в 3.10, и это мощная штука.
Мб разберем как-нибудь хотя бы часть из её возможностей.

case "+":
return add(int(eq[0]), int(eq[2]))
case "-":
return subtract(int(eq[0]), int(eq[2]))
case "*":
return multiply(int(eq[0]), int(eq[2]))
case "/":
return divide(int(eq[0]), int(eq[2]))
main()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Такие вещи еще зачастую пишут через

if __name__ == '__main__':
    main()

На следующей лекции как раз разберем зачем это нужно