pythont编写atm
时间: 2023-08-19 19:07:40 浏览: 76
好的,以下是一个简单的 Python ATM 程序:
```python
class ATM:
def __init__(self, card_number, pin):
self.card_number = card_number
self.pin = pin
def check_balance(self):
print("Your balance is $1000")
def withdraw(self, amount):
new_amount = 1000 - amount
print("You have withdrawn "+str(amount) +". Your remaining balance is "+ str(new_amount))
def main():
card_number = input("Insert your card number: ")
pin = input("Enter your pin: ")
new_user = ATM(card_number, pin)
print("What do you want to do?")
print("1. Check balance")
print("2. Withdraw")
activity = int(input("Enter activity number: "))
if(activity == 1):
new_user.check_balance()
elif(activity == 2):
amount = int(input("Enter the amount to withdraw: "))
new_user.withdraw(amount)
else:
print("Enter a valid number")
main()
```
这个程序使用类来创建一个 ATM 对象,然后根据用户输入的选项执行不同的操作。在这个程序中,我们只是简单地检查余额和提取现金。你可以根据你自己的需求来扩展这个程序。
阅读全文