You are on page 1of 5

PROBLEM

Create a program that reads a number that corresponds to a specific action, chosen by the user
from the choices:

 1 for Deposit;
 2 for Withdraw;
 3 for Exit.
The first part of the program must show the account details of the user, a welcoming message and
the options that can be used (as shown). This block shall be looped every time a process or option is
picked, but the values will be updated depending on the action that is taken:
Account Details:
Name: Sandialen A. Kanda
ID: 1319695
Balance: P250000

Welcome to Bob’s ATM! How may I help you today?


(1) Deposit
(2) Withdraw
(3) Exit

The option 1 should deposit an amount and will be added to the balance, option 2 should
withdraw an amount from the balance, and option 3 should exit the program. Any amount that will
exceed the amount to be withdrawn should show a message “Withdraw amount greater than current
balance!" and when it is negative "ERROR: Withdraw amount less than zero!"

“Pick a process:” should be used as the prompt that will ask the user to input the number. This
part shall be looped as well. A number that is entered by the user which is not within the 3 options
should show a message “ERROR: Process not found!”
SOURCE CODE:
(1) File name: atmApp.py
class atmApp:
#contrucstor to initialize values
def __init__(self, owner, idNum, balance) -> None:
self.runApp = 1
_name = owner
_idNum = idNum
bal = balance

#while loop to keep the program running


while self.runApp == 1:
self.mainMenu(_name, _idNum, bal)

#creates the main menu


def mainMenu(self, name, idNum, bal):
#main menu options list
optionsList = [
"(1) Deposit",
"(2) Withdraw",
"(3) Exit"
]

print("--------------------------")
print("Account Details:")
print("Name: " + name)
print("ID: " + idNum)
print("Balance: P" + str(bal))
print("--------------------------")
print("Welcome to Bob's ATM! How may I help you today?")

#prints the options from a list


for x in optionsList:
print(x)

print()
print(prcss := input("Pick a process: "))
self.processBranching(prcss, name, idNum, bal)

#user can pick process they want


def processBranching(self, prcss, name, idNum, bal):
if prcss == "1":
self.deposit(name, idNum, bal)
elif prcss == "2":
self.withdraw(name, idNum, bal)
elif prcss == "3":
self.exitApp()
else:
print("ERROR: Process not found!")
self.mainMenu(name, idNum, bal)

#users can deposit any amount


def deposit(self, name, idNum, bal):
print(dpstAmt := input("Insert deposit amount: "))
bal += int(dpstAmt)
self.mainMenu(name, idNum, bal)

#users can withdraw any amount within their balance range


def withdraw(self, name, idNum, bal):
print(wtdrwAmt := input("Insert withdrawal amount: "))

#check if withdraw amount is neither less than 0 or greater than current


amount
if float(wtdrwAmt) > bal:
print("ERROR: Withdraw amount greater than current balance!")
self.withdraw(name, idNum, bal)
elif float(wtdrwAmt) < 0:
print("ERROR: Withdraw amount less than zero!")
self.withdraw(name, idNum, bal)
else:
bal -= int(wtdrwAmt)
self.mainMenu(name, idNum, bal)

#exits app by setting variable to 0


def exitApp(self):
self.runApp = 0

# main = atmApp(
# "Sandialen Kanda III",
# "731491",
# 250000
# )
# main.__init__

(2) Filename: tests.py


from atmApp import atmApp

name = "Sandialen A. Kanda"


idNum = "1319695"
bal = 250000

atmApp(name, idNum, bal)


OUTPUT
FLOW CHART
Start

Initialize values and


variables:
_name, _idNum, _bal

Creates the main menu:


Prints:
Account Details:
Name: + name
ID: + idNum
Balance: P + bal

Welcome to Bob's ATM! How may I help you today?

Prints optionsList:
"(1) Deposit",
"(2) Withdraw",
"(3) Exit"

User picks process


they want

User deposits
“1”
True an amount: dpstAmt is added to bal
dpstAmt

False

True User withdraws any Prints “ERROR:


“2” amount within their wtdrwAmt True Withdraw amount
balance range: > bal greater than current
wtdrwAmt balance!"
False
False
True
Exits program “3”
Prints "ERROR:
wtdrwAmt True
Withdraw amount
<0 less than zero!"

End
False False
wtdrwAmt is
subtracted to bal

Prints “ERROR: Process


not found!”

You might also like