-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (41 loc) · 1.6 KB
/
main.py
File metadata and controls
56 lines (41 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
return "Ошибка: деление на ноль."
else:
return a / b
def calculator():
print("Добро пожаловать в программу Калькулятор!\n")
while True:
num1 = float(input("Введите первое число: "))
num2 = float(input("Введите второе число: "))
print("\nВыберите операцию:")
print("1. Сложение")
print("2. Вычитание")
print("3. Умножение")
print("4. Деление\n")
operation = input("Введите ваш выбор (1-4): ")
if operation == '1':
result = add(num1, num2)
print("\nРезультат сложения: ", result)
elif operation == '2':
result = subtract(num1, num2)
print("\nРезультат вычитания: ", result)
elif operation == '3':
result = multiply(num1, num2)
print("\nРезультат умножения: ", result)
elif operation == '4':
result = divide(num1, num2)
print("\nРезультат деления: ", result)
else:
print("\nНеверный ввод.")
repeat = input("\nХотите продолжить? (Y/N): ")
if repeat.lower() != 'y':
print("\nЗавершаем выполнение программы")
break
calculator()