atm程序代码
时间: 2023-09-23 12:03:47 浏览: 49
以下是一个简单的ATM程序代码示例:
```python
class ATM:
def __init__(self, balance=0):
self.balance = balance
def check_balance(self):
return f"Your current balance is {self.balance}"
def deposit(self, amount):
self.balance += amount
return f"{amount} deposited. Your current balance is {self.balance}"
def withdraw(self, amount):
if amount > self.balance:
return "Insufficient balance"
else:
self.balance -= amount
return f"{amount} withdrawn. Your current balance is {self.balance}"
# Example usage
atm = ATM(1000)
print(atm.check_balance()) # "Your current balance is 1000"
print(atm.deposit(500)) # "500 deposited. Your current balance is 1500"
print(atm.withdraw(200)) # "200 withdrawn. Your current balance is 1300"
```
这段代码定义了一个ATM类,其中包含了检查余额、存款和取款功能。在示例中,我们创建了一个ATM对象,并使用该对象调用上述方法来检查余额、存款和取款。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)