Created
June 3, 2025 22:04
-
-
Save Grimitch/212425b1161f2bf40a935bd3577438fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "Ошибка: деление на ноль" | |
return x / y | |
print("Выберите операцию:") | |
print("1. Сложение") | |
print("2. Вычитание") | |
print("3. Умножение") | |
print("4. Деление") | |
while True: | |
choice = input("Введите номер операции (1/2/3/4): ") | |
if choice in ('1', '2', '3', '4'): | |
try: | |
num1 = float(input("Введите первое число: ")) | |
num2 = float(input("Введите второе число: ")) | |
except ValueError: | |
print("Ошибка: введите числа.") | |
continue | |
if choice == '1': | |
print("Результат:", add(num1, num2)) | |
elif choice == '2': | |
print("Результат:", subtract(num1, num2)) | |
elif choice == '3': | |
print("Результат:", multiply(num1, num2)) | |
elif choice == '4': | |
print("Результат:", divide(num1, num2)) | |
else: | |
print("Неверный ввод!") | |
next_calc = input("Хотите продолжить? (да/нет): ") | |
if next_calc.lower() != 'да': | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment