-
Notifications
You must be signed in to change notification settings - Fork 52
HW2_Stepanova #21
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?
HW2_Stepanova #21
Changes from all commits
ede2257
5b9b060
a8fed4f
4d1bea9
f983adf
df46684
f308468
c129d37
4819108
8041362
ae12e2a
ade6c3b
a0bfe15
eaa9954
348d11a
e74f497
66f9d88
941f7df
3bb060c
2d458bd
8b6981a
c9a74b3
9766cc9
1630d7f
5aa3318
e4c1525
48cc41d
f6f3106
5f27938
6bf9d43
b085eb6
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,45 @@ | ||
| ***Программа КАЛЬКУЛЯТОР*** | ||
|
|
||
| Состав разработчиков: Степанова Валерия, Решетникова Галина, Юдин Данил, | ||
| Кичигина Наталья. | ||
|
|
||
| **Описание программы** | ||
|
|
||
| _Степанова В.:_ | ||
|
|
||
| *main()* - представляет собой точку входа в программу, организуя основной цикл выполнения и координацию её основных компонентов. Осуществляет запуск все остальных функций. | ||
| *display()* - функция выводит результат вычислений | ||
| *get_numbers()* - функция принимает на вход выражение | ||
| состоящее из двух чисел в формате int() или float() и символ операции (+,-,*,/). | ||
| Пример: '5 + 6'; '123 / 5' | ||
|
|
||
| _Решетникова Г.:_ | ||
|
|
||
| *calculate(a: float, b: float, operator: str)* - функция принимает на вход два числа и оператор и вычисляет выражение в соотвествии | ||
| с операцией (+,-,*,/). В случае введения иной операции выдает результат "Я умею только складывать, | ||
| вычитать, умножать и делить". В случае деления на ноль выдает результат "Ошибка: Деление на ноль!". | ||
| Помимо этого добавлен вывод результата print(f"Результат: {result}"). | ||
|
|
||
| _Юдин Д.:_ | ||
|
|
||
| *end()* -- булева функция, которая спрашивает пользователя, хочет ли он | ||
| продолжить вычисления. Функция выводит FALSE, если пользователь отвечает | ||
| "нет". | ||
|
|
||
| _Кичигина Н.:_ | ||
|
|
||
| *operation(expression)* --Функция operation(expression) принимает на вход одну | ||
| переменную в формате str()- выражение для вычисления. | ||
| Далее функция split разделяет данную строку на подстроки по разделителю | ||
| (по умолчанию- символ пробела). | ||
| Переменным a,oper,b поочерёдно присваиваются значения этих подстрок. | ||
| Переменным a,b указывается тип float(). | ||
| Функция возвращает три переменных: a-первое число выражения, тип float(); | ||
| b- второе число выражения, тип float(); | ||
| oper- арифметический знак выражения, | ||
| тип str() | ||
|
|
||
| Наш групповой звонок! | ||
|
|
||
|  | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,70 @@ | ||||||||||||||||
| # функция, которая спрашивает, хочет ли человек продолжить расчет | ||||||||||||||||
| def end(): | ||||||||||||||||
| while True: | ||||||||||||||||
| x = input('Вы хотите совершить еще один расчет?\nОтвет: да/нет ').lower() | ||||||||||||||||
| if x == 'да': | ||||||||||||||||
| return False | ||||||||||||||||
| break | ||||||||||||||||
| elif x == 'нет': | ||||||||||||||||
| return True | ||||||||||||||||
| break | ||||||||||||||||
| else: | ||||||||||||||||
| print('Неподходящий ответ') | ||||||||||||||||
|
|
||||||||||||||||
| # функция возвращает F или T, соотвественно, в цикле ее можно указать в виде if end(): | ||||||||||||||||
| # if end(): | ||||||||||||||||
| # print('Конец программы') | ||||||||||||||||
| # else: | ||||||||||||||||
| # print('Расчет дальше') | ||||||||||||||||
|
|
||||||||||||||||
| def get_numbers(): | ||||||||||||||||
| exp = (input("Введите выражение: ")) | ||||||||||||||||
| return exp | ||||||||||||||||
|
Comment on lines
+21
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.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| def operation(expression): | ||||||||||||||||
| a,oper,b=expression.split() | ||||||||||||||||
| a=float(a) | ||||||||||||||||
| b=float(b) | ||||||||||||||||
| return(a,b,oper) | ||||||||||||||||
|
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. круто, что вынесли это отдельно! |
||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| def calculate(a, b, oper): | ||||||||||||||||
| if oper == "+": | ||||||||||||||||
| result = a + b | ||||||||||||||||
| elif oper == "-": | ||||||||||||||||
| result = a - b | ||||||||||||||||
| elif oper == "*": | ||||||||||||||||
| result = a * b | ||||||||||||||||
| elif oper == "/": | ||||||||||||||||
| if b != 0: | ||||||||||||||||
| return a / b | ||||||||||||||||
| else: | ||||||||||||||||
| return "Ошибка: Деление на ноль!" | ||||||||||||||||
|
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. круто, что вспомнили про особый случай с делением! 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. Здравствуйте, Артём!
Comment on lines
+39
to
+42
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. в случаях, когда обе ветки в if/else заканчиваются
Suggested change
|
||||||||||||||||
| else: | ||||||||||||||||
| result = "Я умею только складывать, вычитать, умножать и делить" | ||||||||||||||||
| return result | ||||||||||||||||
|
|
||||||||||||||||
| def display(result): | ||||||||||||||||
| print("Результат: ", result) | ||||||||||||||||
|
|
||||||||||||||||
| def main(): | ||||||||||||||||
| while True: | ||||||||||||||||
| # Получение чисел | ||||||||||||||||
| exp = get_numbers() | ||||||||||||||||
|
|
||||||||||||||||
| # Запрос операции | ||||||||||||||||
| a,b,oper = operation(exp) | ||||||||||||||||
|
|
||||||||||||||||
| # Вычисление | ||||||||||||||||
| result = calculate(a, b, oper) | ||||||||||||||||
|
|
||||||||||||||||
| # Вывод результат | ||||||||||||||||
| display(result) | ||||||||||||||||
|
|
||||||||||||||||
| #Реализует функцию end() | ||||||||||||||||
| if end(): | ||||||||||||||||
| print('Конец программы') | ||||||||||||||||
| break | ||||||||||||||||
|
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. здесь хочется увеличить отступ у комментариев на ещё один уровень |
||||||||||||||||
|
|
||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||
| main() | ||||||||||||||||
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.
огонь!
зачем вам
breakпослеreturn?)