-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (50 loc) · 1.79 KB
/
Copy pathmain.py
File metadata and controls
68 lines (50 loc) · 1.79 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
57
58
59
60
61
62
63
64
65
66
67
68
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
def add(x, y):
"""Сложение двух чисел."""
return x + y
def subtract(x, y):
"""Вычитание двух чисел."""
return x - y
def multiply(x, y):
"""Умножение двух чисел."""
return x * y
def divide(x, y):
"""Деление двух чисел."""
if y == 0:
return "Деление на ноль невозможно!"
else:
return x / y
while True:
print("Выберите операцию:")
print("1. Сложение")
print("2. Вычитание")
print("3. Умножение")
print("4. Деление")
print("5. Выход")
choice = input("Введите номер операции (1/2/3/4/5): ")
if choice in ('1', '2', '3', '4'):
try:
num1 = float(input("Введите первое число: "))
num2 = float(input("Введите второе число: "))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
except ValueError:
print("Неверный ввод. Пожалуйста, введите число.")
elif choice == '5':
break
else: