ساختن یک سیستم خودپرداز ساده در پایتون: یک مرور اتفاقی

هی همه،
بنابراین، من می خواستم با همه شما به اشتراک بگذارم که چگونه این سیستم ساده خودپرداز را در پایتون جمع آوری کردم. این چیز جالبی نیست، اما کار را انجام می دهد!
اول از همه، من چند دیکشنری راه اندازی کردم تا شماره کارت، پین و موجودی حساب را پیگیری کنم. چیزی شبیه این به نظر می رسد:
import time
# Dictionary to store card numbers and corresponding PINs
cardsWithPin = {123456789: 123, 987654321: 345, 234567890: 567, 345678901: 789}
# Dictionary to store card numbers and corresponding account balances
cardsWithAmt = {123456789: 50000, 987654321: 5000, 234567890: 7890, 345678901: 100000}
سپس، من توابعی را برای عملیات های مختلف مانند بررسی موجودی، برداشت پول و واریز پول ایجاد کردم. در اینجا یک قطعه از آن است:
# Function to check account balance
def checkBalance(cardNo):
print(f"Current Balance: Rs.{cardsWithAmt.get(cardNo)}/-")
time.sleep(0.6)
# Function to withdraw money
def withdraw(cardNo):
# Some code here...
# Function to deposit money
def deposit(cardNo):
# Some code here...
# Main ATM system function
def atmSystem():
# Some code here...
این atmSystem
عملکرد جایی است که جادو اتفاق می افتد. این کل تجربه ATM از ورود به سیستم گرفته تا انجام تراکنش ها و خروج از سیستم را مدیریت می کند.
def atmSystem():
print("======================WELCOME==========================")
# Some code here...
و تقریباً همین است! این یک برنامه ساده است که آنچه را که قرار است انجام دهد انجام می دهد. البته، همیشه جای پیشرفت وجود دارد، اما در حال حاضر، از این که چگونه به نتیجه رسیدهام راضی هستم.
با خیال راحت به کد کامل نگاه کنید و با آن بازی کنید. اگر پیشنهادی برای بهبود یا ویژگی های جالب برای اضافه کردن دارید، من همه گوش هستم!
بعد به شما ملحق میشم!
و این هم کد کامل:
import time
# Dictionary to store card numbers and corresponding PINs
cardsWithPin = {123456789: 123, 987654321: 345, 234567890: 567, 345678901: 789}
# Dictionary to store card numbers and corresponding account balances
cardsWithAmt = {123456789: 50000, 987654321: 5000, 234567890: 7890, 345678901: 100000}
# Function to check account balance
def checkBalance(cardNo):
print(f"Current Balance: Rs.{cardsWithAmt.get(cardNo)}/-")
time.sleep(0.6)
# Function to withdraw money
def withdraw(cardNo):
# Some code here...
# Function to deposit money
def deposit(cardNo):
# Some code here...
# Main ATM system function
def atmSystem():
print("======================WELCOME==========================")
cardNo = int(input("Enter your card number:"))
if cardNo not in cardsWithPin:
print("Invalid card number...")
return
pin = int(input("Enter pin: "))
if cardsWithPin.get(cardNo) != pin:
print("Invalid pin...")
return
time.sleep(0.5)
print("Login Successful...")
time.sleep(0.4)
while True:
print("""Please select any option:
1). Deposit
2). Withdraw
3). Check Balance
4). Quit
""")
operation = int(input("Select option: "))
match(operation):
case 1:
print("You selected Money Deposit...")
deposit(cardNo)
case 2:
print("You selected Withdraw...")
withdraw(cardNo)
case 3:
print("You selected Check Balance...")
checkBalance(cardNo)
case 4:
time.sleep(0.3)
print("Thank you for using the ATM. Goodbye!")
return
case _:
print("Invalid option")
time.sleep(0.6)
# Run the ATM system
atmSystem()
با خیال راحت آن را در محیط پایتون خود کپی و جایگذاری کنید و آن را امتحان کنید! اگر سوال یا پیشنهادی دارید به من اطلاع دهید.