yaro = SavingAccount("M111","Yaro",100) ^ SyntaxError: invalid syntax
时间: 2023-07-24 10:14:14 浏览: 87
Apologies for the confusion. It seems there is a syntax error in your code. The line where you create the `yaro` instance of the `SavingAccount` class is missing a closing parenthesis. Here's the corrected code:
```python
class Account:
def __init__(self, account_id, name, amount):
self.account_id = account_id
self.name = name
self.amount = amount
def __str__(self):
return f"ID: {self.account_id}, Name: {self.name}, Amount: {self.amount}"
class SavingAccount(Account):
interest_rate = 0.05
def __init__(self, account_id, name, amount):
super().__init__(account_id, name, amount)
def withdraw(self, y):
if self.amount - y < 0:
print("Saving account can't be below 0")
else:
self.amount -= y
def statement(self):
print("ID is: {}, Name: {}, Amount: {}".format(self.account_id, self.name, self.amount))
yaro = SavingAccount("M111", "Yaro", 100)
yaro.withdraw(104)
yaro.statement()
```
Now, when you run this code, it will create an instance of `SavingAccount` named `yaro`, perform a withdrawal, and print the statement correctly.
阅读全文