add main.py and error.py

This commit is contained in:
PeseC 2022-10-29 01:48:17 +04:00
commit 806619e58c
2 changed files with 59 additions and 0 deletions

2
error.py Normal file
View File

@ -0,0 +1,2 @@
class NotFoundError(Exception):
"""Надо вводить щзнак а не числа"""

57
main.py Normal file
View File

@ -0,0 +1,57 @@
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