AttributeError:“帐户”对象没有属性“提取”

时间:2019-09-28 06:57:23

标签: python python-3.7

我收到上述错误。在Jupyter Notebook中签入并删除了空格和缩进错误。 但是,尽管再次导入了Account类,但在该终端中仍然出现下面的类,但仍然出现错误。 如果我打开另一个终端,我不会收到错误消息。 如果我不想打开第二个终端窗口,该怎么办才能确保在第一个“终端”窗口中不会出现错误?

# account.py
"""Account class definition."""
from decimal import Decimal

class Account:
    """Account class for maintaining a bank account balance."""

def __init__(self, name, balance):
    """Initialize an Account object."""

    # if balance is less than 0.00, raise an exception
    if balance < Decimal('0.00'):
        raise ValueError('Initial balance must be >= to 0.00.')

    self.name = name
    self.balance = balance

def withdraw(self, amount):
    """withdraw money from account"""

    # If amount is > balance, raise an exception
    if amount > self.balance:
        raise ValueError('withdrawl amount must <= current Balance')

    # if amount is less than 0.00, raise an exception
    elif amount < Decimal('0.00'):
        raise ValueError('withdrawl amount must be positive.')

    self.balance -= amount

def deposit(self, amount):
    """Deposit money to the account."""

    # if amount is less than 0.00, raise an exception
    if amount < Decimal('0.00'):
        raise ValueError('amount must be positive.')

    self.balance += amount

0 个答案:

没有答案