-
Notifications
You must be signed in to change notification settings - Fork 55
Nekrasova's team pull-request #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
f7ba5dc
e9fc7ba
32381db
d3ca03d
b672eb9
4f7eae8
22d6854
98ee437
9c2723d
1b1799a
aa0d07d
477c539
beb1684
a94dcb2
268db30
6cc9aea
7f59f19
a35c2d6
61d8bb7
d2d7380
977549a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .idea/* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Basic calculator | ||
| *This repo is for the 2nd homework of Python 2023 course* | ||
|
|
||
| ### Calculator description | ||
| This branch (HW2_nekrasova) contains calculator.py script designed to operate with two numbers via one of the following basic mathematical functions: addition, subtraction, multiplication, division. | ||
| Right after start script waits for the user to enter a mathematical expression like '2 * 2'. Expression is then splitted by spaces and calculated corresponding to function according to the specified operator. | ||
| The script handles both int and float types of numbers. It also handles devision by 0. | ||
|
|
||
| ### Installation | ||
| Calculator is a straight forward script that does not need any prerequisites apart from installed Python 3. To get started use your CLI and execute the following commandlet: `python3 calculator.py`. | ||
| After this the script is ready to recieve your mathematical expression. | ||
|
|
||
| ### Development | ||
| This project is leaded by nekrasovadasha22 with contributions from the following people: | ||
| - grishchenkoira | ||
| - anisssum | ||
| - NSapozhnikov | ||
| - Komarov I. | ||
|
|
||
| Feel free to report any bugs encountered to nekrasovadasha22. | ||
|  | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не очень хорошо, что main() определяется до определения подфункций, вызываемых main(). Лучше соблюдать логику кода: сначала определение подфункций, а уже потом больших функций. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хорошая работа! Так что молодцы! Итог: Итог: 10.5 |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,62 @@ | ||||||||||
| def main(expression: str): | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ого, аннотация типов!👍 |
||||||||||
| expression_array = expression.split(' ') | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Если хочется сделать сплит по пробельным символам, то советую такую конструкцию. В случае введения двойного пробела ваш вариант вставит " " в список, а предложенная - нет. 😌 |
||||||||||
| array_of_operands = [] | ||||||||||
|
|
||||||||||
| try: | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Очень уместное и лаконичное использование конструкции try-except для определения типов👍 |
||||||||||
| left_int = int(expression_array[0]) | ||||||||||
| array_of_operands.append(left_int) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Логичнее было бы назвать переменную списком чисел, т.к. операнд - это +, -, /, *, и т.п. |
||||||||||
| except: | ||||||||||
| left_float = float(expression_array[0]) | ||||||||||
| array_of_operands.append(left_float) | ||||||||||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Куда потерялся пробел?😢 |
||||||||||
|
|
||||||||||
|
|
||||||||||
| try: | ||||||||||
| right_int = int(expression_array[2]) | ||||||||||
| array_of_operands.append(right_int) | ||||||||||
| except: | ||||||||||
| right_float = float(expression_array[2]) | ||||||||||
| array_of_operands.append(right_float) | ||||||||||
|
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Снова пробел... |
||||||||||
|
|
||||||||||
| answer = None | ||||||||||
|
|
||||||||||
| if expression_array[1] == '+': | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Уместнее было бы записать операнд в переменную и сравнивать её значение, но это так, перфекционизм |
||||||||||
| answer = add(array_of_operands) | ||||||||||
|
|
||||||||||
| elif expression_array[1] == '-': | ||||||||||
| answer = substruct(array_of_operands) | ||||||||||
|
|
||||||||||
| elif expression_array[1] == '*': | ||||||||||
| answer = multiple(array_of_operands) | ||||||||||
| elif expression_array[1] == '/': | ||||||||||
| answer = divide(array_of_operands) | ||||||||||
|
|
||||||||||
| print(answer) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def add(arr_of_operands: list): | ||||||||||
| return arr_of_operands[0]+arr_of_operands[1] | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
По PEP8 тут нужны пробелы)) Сейчас на оценку не влияет, но в будущем обращайте внимание) |
||||||||||
|
|
||||||||||
| def substruct(arr_of_operands: list): | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Нейминг😌 |
||||||||||
| # substruct | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Такие комментарии лучше удалять из кода, если они не несут дополнительной информации 😌 |
||||||||||
| return arr_of_operands[0]-arr_of_operands[1] | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| def multiple(arr_of_operands: list): | ||||||||||
| answer = arr_of_operands[0] * arr_of_operands[1] | ||||||||||
| return answer | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def divide(arr_of_operands: list): | ||||||||||
| if arr_of_operands[1] != 0: | ||||||||||
| answer = arr_of_operands[0]/arr_of_operands[1] | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| return answer | ||||||||||
| else: | ||||||||||
| answer = 'Деление на 0!' | ||||||||||
|
Comment on lines
+53
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хороший вариант сказать пользователю о делении на ноль!) |
||||||||||
| return answer | ||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
| current_expression = input() | ||||||||||
| main(current_expression) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README малоинформативный. Не указан вклад каждого из членов команды, нет примеров использования программы: что она получает на вход и что выдает на выходе.
Здорово, что дана команда для вызова из терминала!