Skip to content

Hw2 tuliavko #11

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 19 commits into
base: main
Choose a base branch
from
Open

Conversation

vladislavi27
Copy link

This is the repo for the second homework of the BI Python 2023 course:
Badmadashiev Dorzhi
Vedekhina Veronika
Tuliavko Vlada
Matveeva Ksenia
Vaganova Polina

@SidorinAnton
Copy link

В целом отлично! Коммиты названы хорошо. Отдельное спасибо за PEP8!

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

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 мы бы все-равно хотели что-то да рассчитать.

return num1 / num2

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, например ))


def main():
task = input('Enter your 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()

task = input('Enter your expression:')
task = task.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

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

Choose a reason for hiding this comment

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

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

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

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)


### 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 :)

Comment on lines +17 to +19
# input expressions
Enter your expression:1 + 2
3

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants