from random import randint
ENLIGHTENMENT_CARMA_LEVEL = 777
class IamGodError(Exception):
pass
class DrunkError(Exception):
pass
class CarCrashError(Exception):
pass
class GluttonyError(Exception):
pass
class DepressionError(Exception):
pass
class SuicideError(Exception):
pass
def one_day():
day = 1
total_carma = 0
while day == 1:
total_carma += randint(1, 7)
dice = randint(1, 13)
if dice == 1:
try:
pass
except IamGodError('ой ой'):
print(f'Поймано исключение типа')
elif dice == 2:
try:
pass
except:
raise CarCrashError('бип бип')
elif dice == 3:
try:
pass
except:
raise GluttonyError('обжора')
elif dice == 4:
try:
pass
except:
raise CarCrashError('бип бип')
elif dice == 5:
try:
pass
except:
raise DrunkError('+1000 алко')
elif dice == 6:
try:
pass
except:
raise SuicideError('...')
if total_carma == 777:
break
one_day()
#########
elif dice == 4:
raise CarCrashError('бип бип')
#########
try:
one_day()
except SuicideError:
do_something()
except CarCrashError:
do_something()
# и т.д.
#########
elif dice == 4:
return some_id_data
#########
reactions = {
some_id_data: do_something # <- объект функции
}
result = one_day()
if result == some_id_data:
do_something()
result = one_day()
reactions[some_id_data]()
ENLIGHTENMENT_CARMA_LEVEL = 777
def one_day():
dice = random.randint(1, 13)
karma = random.randint(1, 7)
if dice == 1:
try:
raise BaseException("IamGodError")
except BaseException as exc:
print(f'Исключение класса - {type(exc)} | параметры {exc.args}')
if dice == 2:
try:
raise BaseException("DrunkError")
except BaseException as exc:
print(f'Исключение класса - {type(exc)} | параметры {exc.args}')
if dice == 3:
try:
raise BaseException("CarCrashError")
except BaseException as exc:
print(f'Исключение класса - {type(exc)} | параметры {exc.args}')
if dice == 4:
try:
raise BaseException("GluttonyError")
except BaseException as exc:
print(f'Исключение класса - {type(exc)} | параметры {exc.args}')
if dice == 5:
try:
raise BaseException("DepressionError")
except BaseException as exc:
print(f'Исключение класса - {type(exc)} | параметры {exc.args}')
if dice == 6:
try:
raise BaseException("SuicideError")
except BaseException as exc:
print(f'Исключение класса - {type(exc)} | параметры {exc.args}')
return karma
total_karma = 0
while True:
print(total_karma)
if total_karma < ENLIGHTENMENT_CARMA_LEVEL:
total_karma += one_day()
else:
break
from random import randint
ENLIGHTENMENT_CARMA_LEVEL = 777
def one_day(carma_now=0):
ENLIGHTENMENT_CARMA_LEVEL = 777
all_day = 0
list_random = ['IamGodError','DrunkError','CarCrashError','GluttonyError','DepressionError','SuicideError',]
while carma_now <= ENLIGHTENMENT_CARMA_LEVEL:
add_karm = randint(1, 7)
carma_now += add_karm
print(f'Карма прибавилась на {add_karm} и стала {carma_now}')
all_day += 1
dice = randint(1,13)
if dice == 1:#или любое число чтобы была вероятность 1 к 13
try:
now_error = list_random[randint(0,5)] #выбираем рандомно наше исключение если выпало число 1
raise Exception(now_error)
except Exception as exc:
peremennaya_error = f'{exc.args}\n'
print(f'Наше исключение {peremennaya_error}')
file_log = open('logirovanie.txt','a',encoding= 'utf-8')
file_log.write(peremennaya_error)
else:
print(f'Мы выбрались из дня сурка кармы стало {carma_now}')
print(f'Дней затрачено {all_day}')
day_surka = one_day()
print(day_surka)