Hey everyone,
So, I wanted to share with you all how I put together this simple ATM system in Python. It's nothing fancy, but it gets the job done!
First off, I set up a couple of dictionaries to keep track of card numbers, PINs, and account balances. It looks something like this:
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}
Then, I created functions for different operations like checking balance, withdrawing money, and depositing money. Here's a snippet of that:
# 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...
The atmSystem function is where the magic happens. It handles the whole ATM experience, from logging in to performing transactions and quitting the system.
def atmSystem():
print("======================WELCOME==========================")
# Some code here...
And that's pretty much it! It's a straightforward program that does what it's supposed to do. Of course, there's always room for improvement, but for now, I'm happy with how it turned out.
Feel free to take a look at the full code and play around with it. If you have any suggestions for improvements or cool features to add, I'm all ears!
Catch you later!
And here's the complete code:
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()
Feel free to copy and paste it into your Python environment and give it a try! Let me know if you have any questions or suggestions.
SOCIAL SHARE CARD GENERATOR