Skip to content

Hw2 tuliavko#11

Open
vladislavi27 wants to merge 19 commits intoPython-BI-2023:mainfrom
vladislavi27:HW2_Tuliavko
Open

Hw2 tuliavko#11
vladislavi27 wants to merge 19 commits intoPython-BI-2023:mainfrom
vladislavi27:HW2_Tuliavko

Conversation

@vladislavi27
Copy link
Copy Markdown

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
Copy Markdown

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

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

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:')
Copy link
Copy Markdown

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(" ")
Copy link
Copy Markdown

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]
Copy link
Copy Markdown

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
}
Copy link
Copy Markdown

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)
Copy link
Copy Markdown

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)

Comment thread HW2_Tuliavko/README.md

### 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.
Copy link
Copy Markdown

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 thread HW2_Tuliavko/README.md
Comment on lines +17 to +19
# input expressions
Enter your expression:1 + 2
3
Copy link
Copy Markdown

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