Как увеличить область отображаемого числа?

Только начал учить Python, и сделать калькулятор но тут он выдает ошибку которую я не могу никак найти

x = float(input())
y = float(input())
operation = str(input())

if operation == "+":
    print (x + y)
elif operation == "-":
    print (x - y)
elif operation == "/" and y != 0.0:
    print (x / y)
elif operation == "*":
    print (x * y)
elif operation == "mod" and y != 0.0:
    print (x // y and x % y)
elif operation == "pow":
    print (x ** y)
elif operation == "div" and y != 0.0:
    print (x % y)
if y == 0.0 and (operation in ('/', 'mod', 'div')):
    print('Деление на 0!')

Данные которые ввожу:

7
399
pow

Ошибка которую он выдает:

Traceback (most recent call last):
  File "jailed_code", line 16, in <module>
    print (x ** y)
OverflowError: (34, 'Numerical result out of range')

Как я понял, что данная ошибка указывает на то что максимум знаков которая она может показать это 34, но как увеличить этот максимум, я не понимаю


Ответы (1 шт):

Автор решения: Namerek
from decimal import Decimal
x = 7
y = 399

try:
    result = x ** y
except OverflowError:
    result = Decimal('{:.2E}'.format(Decimal(x) ** Decimal(y)))
print(result)
# 1.56E+337

from decimal import Decimal
x = 7
y = 20000

result = Decimal('{:.2E}'.format(Decimal(x) ** Decimal(y)))

print(result)
print(result / 50000000)
print(float(result))
# 9.14E+16901
# 1.828E+16894
# inf
→ Ссылка