0

Здраствуйте! Не могу понять, почему не работает этот участок кода:

import decimal
salary = decimal(input())

incomeTax = salary / 100 * 18
militaryTax = incomeTax / 100 * 1.5

result = salary - incomeTax - militaryTax


print('Result:', result)

Ошибка:

Traceback (most recent call last):
  File "43.py", line 4, in <module>
    salary = decimal(input())
TypeError: 'module' object is not callable
5
  • metanit.com/python/tutorial/6.4.php
    – andreymal
    7 окт 2020 в 20:07
  • Спасибо, но яснее не стало. Не могу сам разобраться где я сделал ошибку
    – IRonny
    7 окт 2020 в 20:10
  • salary = decimal.Decimal(input())
    – andreymal
    7 окт 2020 в 20:10
  • либо from decimal import Decimal :)
    – Glebium
    7 окт 2020 в 20:13
  • К сожалению опять ничего не помогло, но появился новый код ошибки: ` Traceback (most recent call last): File "43.py", line 7, in <module> militaryTax = incomeTax / 100 * 1.5 TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float' `
    – IRonny
    7 окт 2020 в 20:21

2 ответа 2

2

Участок кода не работает из-за того, что вы миксуете класс float и класс decimal, что делать не рекомендуется. То есть или все во флоате или все в децимале лучше использовать.

import decimal

d = decimal.Decimal('10.5')
f = float('10.5')
print(d == f) # True


d = decimal.Decimal('10.5557')
f = float('10.5557')
print(d == f) # False
1
import decimal
salary = decimal.Decimal(input())

incomeTax = salary / 100 * 18
militaryTax = incomeTax / 100 * decimal.Decimal(1.5)

result = salary - incomeTax - militaryTax


print('Result:', result)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.