calculator/main.py

58 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from error import NotFoundError
from colorama import init, Fore
init(autoreset=True)
###################################################################
def calc(first, sign, second):
match sign:
case "*":
answer = first * second
case "/":
answer = first / second
case "//":
answer = first // second
case "+":
answer = first + second
case "-":
answer = first - second
case other:
raise NotFoundError("Руки убрал от клавы, пианист блин...")
return answer
###################################################################
while True:
try:
os.system("cls")
print(
Fore.GREEN + "Ваш ответ:",
calc(
first=int(input(Fore.BLUE + "Введите первое число: ")),
sign=input(Fore.BLUE + "Выберите действие: "),
second=int(input(Fore.BLUE + "Введите второе число: ")),
),
)
except ValueError:
os.system("cls")
print(Fore.RED + "Приятель, числа надо вводить, ЧИСЛА!\nЗаново!")
except ZeroDivisionError:
os.system("cls")
print(Fore.RED + "Я тебя сам сейчас на ноль поделю!!!\nЗаново!")
except NotFoundError:
os.system("cls")
print(Fore.RED + "Руки убрал от клавы, пианист блин...\nЗаново!")
pre_end = input(
Fore.BLUE
+ "Для продолжения нажмите Enter.\nЕсли хотите закончить работу введите end.\n "
)
if pre_end == "end":
print(
Fore.BLUE
+ "Спасибо, за то что воспользовались услугами компании ООО'Кальк'.\nС вас много деняг."
)
break