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
34 changes: 34 additions & 0 deletions HW2_Tuliavko/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Calculator for basic arithmetic
This repository contains the script for calculating simple mathematical expressions.

### System requirements:

Key packages and programs:
- [Python](https://www.python.org/downloads/) (version >= 3.9)

### Run calculator:

Execute `extract_interface_residues.py` script provided here to start calculations. Then enter your expression in the line below in following format: the first number, the operation sign + for sum, - for subsctraction, / for division or \* for multiplication and the second number. Note that numbers must be separated by a space from the sign!! To run calculations press the `Enter` key.

Choose a reason for hiding this comment

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

Круто, вот только почему extract_interface_residues.py? Файл же называется calculator.py :)


For example:
```
# launch calculator
python extract_interface_residues.py
# input expressions
Enter your expression:1 + 2
3
Comment on lines +17 to +19

Choose a reason for hiding this comment

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

Вот это тут (в блоке с косыми кавычками) немного лишнее. Обычно в таком блоке пишется код/скрипты и прочее, что через интерфейс можно скопировать и вставить.

```

### Authors:

*This is the repo for the second homework of the BI Python 2023 course*

- Badmadashiev Dorzhi
- Vedekhina Veronika
- Tulyavko Vlada
- Matveeva Ksenia
- Vaganova Polina


![Our team](./team.jpg)

33 changes: 33 additions & 0 deletions HW2_Tuliavko/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# definitions of functions
def subtraction(num1, num2):
return num1 - num2

def addition(num1, num2):
return num1 + num2

def multiplication(num1, num2):
return num1 * num2

def division(num1, num2):
if num2 == 0:
print('Error: division by zero! :(')
else:
return num1 / num2
Comment on lines +12 to +15

Choose a reason for hiding this comment

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

В целом идея неплохая, но 2 момента:

  1. Лучше уж тогда не print, потому что код не остановится. Вы же пишете эту функцию, чтоб получить результат деления. А в случае 0 вам вернется None и дальше где-нибудь программа упадет. Так что конкретно в этом случае можно либо return (но тоже плохо, т.к. мы ожидаем получить число), либо (если прям хочется перезаписать ошибку) делать raise. Но об этом мы поговорим во 2-ом семестре :)
  2. В целом-то можно даже и не обрабатывать :)
    Ну то есть вот пользователь ввел 0 --> программа упала с ZeroDivisionError. Ожидаемое поведение :)
    У нас тут нет какого-то варианта, чтоб при 0 мы бы все-равно хотели что-то да рассчитать.


def main():
task = input('Enter your expression:')

Choose a reason for hiding this comment

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

task? ))
Чем не понравилось название expression, например ))

task = task.split(" ")

Choose a reason for hiding this comment

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

В целом split по умолчанию разбивает по пробелам, так что можно просто .split()

num1, num2 = float(task[0]), float(task[2])
mode = task[1]

Choose a reason for hiding this comment

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

имхо, вместо mode -- operator

return operations[mode](num1, num2)


# dictionary with functions names
operations = {'/': division,
'-': subtraction,
'+': addition,
'*': multiplication
}
Comment on lines +25 to +30

Choose a reason for hiding this comment

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

Строго говоря, эта штука является константой, поэтому имеет смысл назвать её прописными буквами:
operations --> OPERATIONS

# start calculations
result = main()
print(result)
Comment on lines +32 to +33

Choose a reason for hiding this comment

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

Тут бы топ было бы сделать вот так:

if __name__ == '__main__':
    result = main()
    print(result)

Binary file added HW2_Tuliavko/team.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 0 additions & 49 deletions README.md

This file was deleted.