-
Notifications
You must be signed in to change notification settings - Fork 56
Hw2 voskoboinikov #13
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
396fe5d
9299f61
cd8d54f
b1556f0
5ade8b7
d1a3bf5
d598390
657f656
5bfe149
7344c07
9c530db
8c07952
922b195
4b83035
ba1084c
5fe0cc2
e3b39a2
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,23 @@ | ||
# HW2_Git_and_python | ||
|
||
### Project Description | ||
|
||
Данный проект содержит в себе мини-программу `calculator.py`, на вход которой через пробел подается **2 числа** типа *float* или | ||
*integer* и одна из четырех операций (`+ - * /`), которую нужно выполнить с этими числами. | ||
|
||
**Примеры**: `5 + 3`, `2 / 10` | ||
|
||
### How to use | ||
|
||
Чтобы запустить программу, необходимо в командной строке ввести `python3 calculator.py`, находясь в папке с проектом, | ||
после чего следовать подсказкам на экране. | ||
|
||
Чтобы выйти из программы, необходимо ввести команду `exit`. | ||
|
||
### The Team | ||
|
||
Александр Воскобойников - Team leader | ||
|
||
Михаил Гринберг, Артем Васильев, Шакир Сулейманов, Гуля Мурадова - Wonderful developers team | ||
|
||
 |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def addition(a, b): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return(a + b) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. По PEP8 после функции делают 2 пропуска строки |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def subtraction(a, b): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return(a - b) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 multiplication(a, b): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return(a * b) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 division(a, b): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return(a / b) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 calc_parser(calc_string): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
calc_list = calc_string.split(' ') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
calc_list[0] = float(calc_list[0]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
calc_list[2] = float(calc_list[2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return calc_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
calculator_func_dict = {'-': subtraction, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'*': multiplication, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'+': addition, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'/': division} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+19
to
+22
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. 👍 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
calc_string = input('Enter your expression: ') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
while calc_string != 'exit': | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Здорово, что сделали возможность проводить столько вычислений, сколько нужно пользователю👍 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
command = calc_parser(calc_string)[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. Можно один раз вызвать функцию calc_parser() и потом разом записать в переменные элементы в список, а не трижды ее вызывать. Так работает, но выглядит неоптимально.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if command in calculator_func_dict: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
print(calculator_func_dict[command](calc_parser(calc_string)[0], calc_parser(calc_string)[2])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
print('Seems like an invalid expression. Please, enter valid expression!') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
calc_string = input('Enter your expression: ') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
print('See you next time!') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+24
to
+35
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.
скобки у return не нужны