Spaces:
Sleeping
Sleeping
File size: 4,987 Bytes
2486fa0 f60c2ba 5f4e439 2486fa0 0170736 2486fa0 a752734 df5dcbf 0170736 2486fa0 0170736 2486fa0 665573c b968749 0170736 b968749 0170736 665573c 0170736 665573c 2486fa0 a01a313 665573c 0170736 665573c a01a313 b968749 f81b6fa b968749 f81b6fa 0170736 f81b6fa 0170736 f81b6fa 0170736 f81b6fa b968749 f81b6fa 0170736 f81b6fa 0170736 f81b6fa a64e6e1 665573c f81b6fa 0170736 f81b6fa 0170736 f81b6fa 2d11685 b968749 a01a313 b968749 a64e6e1 b968749 bdd8bb9 b968749 665573c b968749 2d11685 665573c bdd8bb9 a64e6e1 f81b6fa b968749 a64e6e1 b968749 a64e6e1 7c2649a b968749 a64e6e1 b968749 9f00d64 b968749 0170736 b968749 0170736 b968749 0170736 b968749 dad2784 b968749 dad2784 b968749 dad2784 a64e6e1 b968749 0170736 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
import streamlit as st
import json
# Function to load user data from a file
@st.cache(allow_output_mutation=True)
def load_user_data():
try:
with open("user_data.json", "r") as file:
data = json.load(file)
return data
except FileNotFoundError:
return {}
# Function to save user data to a file
@st.cache(allow_output_mutation=True)
def save_user_data(data):
with open("user_data.json", "w") as file:
json.dump(data, file)
# Function to display a separator line
def display_separator():
st.write('-' * 50)
# Function to display a welcome message
def display_welcome_message():
st.write("Welcome to the ATM MACHINE")
# Function to display a message with a border
def display_message(message, emoji="π"):
display_separator()
st.write(f"{emoji} {message} {emoji}")
display_separator()
# Function to display the user's balance
def display_balance(user_data):
display_separator()
st.write(f"π° Current Balance: {user_data['amount']} RUPEES π°")
display_separator()
# Function to display the main menu options
def display_menu():
st.write('\nSelect an option:')
st.write('1. View Balance (B)')
st.write('2. Withdraw Cash (W)')
st.write('3. Deposit Cash (D)')
st.write('4. Change PIN (P)')
st.write('5. Quit (Q)')
# Function to handle balance inquiry
def view_balance(user_data):
display_balance(user_data)
# Function to handle cash withdrawal
def withdraw_cash(user_data):
amount_to_withdraw = st.number_input('Enter the amount to withdraw:', step=10, format='%d')
if amount_to_withdraw % 10 != 0:
display_message('π‘ Amount must be in multiples of 10 π‘', "πΈ")
elif amount_to_withdraw > user_data['amount']:
display_message('β Insufficient balance β', "πΈ")
else:
user_data['amount'] -= amount_to_withdraw
save_user_data(user_data)
display_balance(user_data)
display_message(f'πΈ Withdrawal successful: {amount_to_withdraw} RUPEES πΈ', "πΈ")
# Function to handle cash deposit
def deposit_cash(user_data):
amount_to_deposit = st.number_input('Enter the amount to deposit:', step=10, format='%d')
if amount_to_deposit % 10 != 0:
display_message('π‘ Amount must be in multiples of 10 π‘', "πΈ")
else:
user_data['amount'] += amount_to_deposit
save_user_data(user_data)
display_balance(user_data)
display_message(f'πΈ Deposit successful: {amount_to_deposit} RUPEES πΈ', "πΈ")
# Function to handle PIN change
def change_pin(user_data):
new_pin = st.text_input('Enter a new PIN:', type='password')
confirm_pin = st.text_input('Confirm new PIN:', type='password')
if new_pin == confirm_pin:
user_data['pin'] = new_pin
save_user_data(user_data)
display_message('π PIN successfully changed π', "π")
else:
display_message('β PINs do not match. Please try again. β', "β")
# Main Program
display_welcome_message()
# Input user name
name = st.text_input('Enter your name:').lower()
user_data = load_user_data()
if user_data and name in user_data:
# Existing user
pass
else:
# New user; create an entry with default values
user_data[name] = {'pin': '', 'amount': 0}
save_user_data(user_data)
display_message(f'Welcome, {name.capitalize()}! You are a new user.')
# If the user is new, prompt to create a new PIN
if not user_data[name]['pin']:
new_pin = st.text_input('Create a new PIN:', type='password')
user_data[name]['pin'] = new_pin
save_user_data(user_data)
display_message('PIN created successfully!')
# comparing pin
count = 0
while count < 3:
display_separator()
pin = st.text_input('Please enter your PIN:', type='password')
if pin.isdigit() and pin == user_data[name]['pin']:
break
else:
count += 1
display_message('β Invalid PIN. Please try again. β', "β")
# in case of a valid pin - continuing, or exiting
if count == 3:
display_message('β 3 UNSUCCESSFUL PIN ATTEMPTS, EXITING. YOUR CARD HAS BEEN LOCKED β', "β")
st.stop()
display_message(f'π LOGIN SUCCESSFUL, CONTINUE {name.capitalize()}! π', "π")
# Main menu
while True:
display_menu()
response = st.selectbox('Select an option:', ['View Balance (B)', 'Withdraw Cash (W)', 'Deposit Cash (D)', 'Change PIN (P)', 'Quit (Q)'])
if response == 'View Balance (B)':
view_balance(user_data)
elif response == 'Withdraw Cash (W)':
withdraw_cash(user_data)
elif response == 'Deposit Cash (D)':
deposit_cash(user_data)
elif response == 'Change PIN (P)':
change_pin(user_data)
elif response == 'Quit (Q)':
save_user_data(user_data)
display_message('Thank you for using our ATM. Have a great day!')
st.stop()
else:
display_message('β Invalid response. Please try again. β', "β")
|