Skip to content
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
25 changes: 25 additions & 0 deletions HW_Kokinos/README.md
Copy link

Choose a reason for hiding this comment

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

Привет! (´• ω •`)ノ
Отличная работа, молодцы! Комментарии к коду вы найдете ниже.

  • О README.md: было бы здорово добавить в ридми примеры того, как использовать ваш тул (например, что нужно вводить 3 + 5 через пробел, так как без него падает ошибка) и написать конкретные команды по скачиванию. Это займет немного места, а человеку, который хочет использовать ваш тул, будет приятно)

  • О коммитах и структуре репозитория: Стоит похвалить команду за осмысленные названия коммитов! Так держать! Однако названия коммитов лучше писать с заглавной буквы + стоит избегать давать коммитам длинные названия как здесь 'create file calculator.py \n\n add additional function'

О коде будет комментарий чуть ниже в виде построчного ревью.
Баллы: 10/10 (README) + 10/10 (Forks) + 79/80 (код и коммиты) + 10 доп. =
= 99/100 + 10 доп. = 109 баллов

Будьте внимательнее, ветка, PR и папка должны называться HW2_Kokinos.

Вы проделали большую работу. Молодцы! (´。• ω •。`)
(тимлид, не забудь показать ревью всей команде)

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Mathematical Expression Calculator

This is a simple Python console program that calculates mathematical expressions with two operands. It accepts a string as input, which contains a mathematical expression with two numbers (integers or floats) and one of the four operators (+, -, \*, /). The program then calculates the result and displays it on the screen.

### *Features*
___
- Supports four basic arithmetic operations (+, -, \* , /)
- Handles both integers and floats
- Checks for division by zero errors
- Provides error handling for invalid input
### *Requirements*
___
- Python 3.6 or later
### *To install*
___
- Clone the repository or download the zip file
- Make sure Python 3 is installed on your machine
#### *Developed by*
___
- Gorenkova Anastasiia (create main function)
- Kokinos Elena (create addition function)
- Parfenova Polina (create multiple function)
- Shchukina Elza (create difference function)
- Zhidkin Roman (create division function)
![team photo](imgs/team_photo.jpg)
33 changes: 33 additions & 0 deletions HW_Kokinos/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def main(expression):
parts = expression.split()
operator = parts[1]
num1, num2 = float(parts[0]), float(parts[2])
result = 0
Copy link

Choose a reason for hiding this comment

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

Можно не задавать переменную result по дефолту 0. В любом случае вы её всегда создаете при вызове функций заново. Это опасно ещё и тем, что при введении такого выражения 7 & 9, которое не заложено программой, она выдаст 0 как правильный ответ.

if operator == '+':
result = addition(num1, num2)
elif operator == '-':
result = difference(num1, num2)
elif operator == '*':
result = multiple(num1, num2)
elif operator == '/':
if num2==0:
return 'На ноль делить нельзя!'
Copy link

Choose a reason for hiding this comment

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

Молодцы, что подумали о случае деления на ноль, но в питоне итак есть свой особый тип ошибок ZeroDivisionError, программа будет кидать её даже, если вы не поставите условие, поэтому можно не писать дополнительных проверок. Также в данном случае функция обычно возвращает числа, а здесь в качестве результата - строка.

result = deviation(num1, num2)
return result

def difference(a, b):
Copy link

Choose a reason for hiding this comment

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

Стоит избегать однобуквенных названий переменных, как a/b и x/y. У вас отлично написано в главной функции num1 и num2. Стоит делать код с названиями переменных в одном стиле (-1 балл).

return (a - b)
Copy link

Choose a reason for hiding this comment

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

Можно убрать скобки из всех return, они не повлияют на правильность исполнения кода.


def multiple(a, b):
return (a * b)

def deviation (x, y):
Copy link

Choose a reason for hiding this comment

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

По документации PEP8 тут не нужен пробел между названием функции и аргументами. Наверняка вы уже познакомились с классными ребятами black и flake8 (¬‿¬).

return (x/y)

def addition(a, b):
return (a + b)

print(main(input("Введите выражение: ")))
Copy link

Choose a reason for hiding this comment

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

Ридми написан на английском языке, поэтому лучше придерживаться английского языка при написании предупреждений и взаимодействии с пользователем.




Binary file added HW_Kokinos/imgs/team_photo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.