ATM取款机python
时间: 2024-01-04 10:20:07 浏览: 83
基于python语言的ATM存取款模拟系统(源码+演示视频)
5星 · 资源好评率100%
以下是一个基于Python开发的ATM取款机模拟系统的示例代码:
```python
class Card(object):
def __init__(self, cardid, cardpasswd, cardmoney):
self.cardid = cardid # 信用卡号
self.cardpasswd = cardpasswd # 信用卡密码
self.cardmoney = cardmoney # 卡内余额
self.cardlock = False # 是否被锁定
class ATM(object):
def __init__(self):
self.card_list = [] # 存储所有的信用卡对象
def register(self, cardid, cardpasswd, cardmoney):
card = Card(cardid, cardpasswd, cardmoney)
self.card_list.append(card)
print("注册成功!")
def login(self, cardid, cardpasswd):
for card in self.card_list:
if card.cardid == cardid and card.cardpasswd == cardpasswd:
if card.cardlock:
print("该卡已被锁定,请联系银行解锁!")
else:
self.menu(card)
break
else:
print("卡号或密码错误!")
def menu(self, card):
while True:
print("1. 存款")
print("2. 取款")
print("3. 查询余额")
print("4. 退出")
choice = input("请输入操作选项:")
if choice == "1":
self.deposit(card)
elif choice == "2":
self.withdraw(card)
elif choice == "3":
self.check_balance(card)
elif choice == "4":
print("退出成功!")
break
else:
print("无效的选项,请重新输入!")
def deposit(self, card):
amount = float(input("请输入存款金额:"))
card.cardmoney += amount
print("存款成功!")
def withdraw(self, card):
amount = float(input("请输入取款金额:"))
if amount > card.cardmoney:
print("余额不足!")
elif amount % 100 != 0:
print("取款金额必须为整百元!")
else:
card.cardmoney -= amount
print("取款成功!")
def check_balance(self, card):
print("当前余额为:", card.cardmoney)
# 示例代码的使用
atm = ATM()
atm.register("1234567890", "123456", 1000)
atm.login("1234567890", "123456")
```
阅读全文