def transfer():
print ("You've chosen to transfer money.")
transAccFrom = int(input("From which account you want to transfer?\n1.Jack 2.Smith 3.Suzy 4.Craig 5.Vic :"))
transMoney = float(input("How much you want to tranfer?"))
transAccTo = int(input("To which account you want to transfer?\n1.Jack 2.Smith 3.Suzy 4.Craig 5.Vic :"))
#These are asked to know from which acc to to which acc the user wants to transefer.
if (transAccFrom == 1):
if (transMoney > c1.balance):
print ("The process can't be done. Please check your account balance.")
#Since balance of the account that is sending money from isn't enough, non process is being done.
else:
c1.balance = c1.balance - transMoney
if (transAccTo == 1):
c1.balance = c1.balance + transMoney
print ("You have transfered money from Jack's Acc to Jack's Acc. Balance of Jack's Acc is "+str(c1.balance)+". Thank you for using our bank.")
#After eliminate the amount of money that is determined to be transfered from, the amount of money is directly added to account that the money is supposed to be transfered to. Below steps are the same stages.
elif (transAccto == 2):
c2.balance = c2.balance + transMoney
print ("You have transfered money from Jack's Acc to Smith's Acc. Remaining value of Jack's Acc is "+str(c1.balance)+". Balance of Smith's Acc is "+str(c2.balance)+" Thank you for using our bank.")
elif (transAccTo == 3):
c3.balance = c3.balance + transMoney
print ("You have transfered money from Jack's Acc to Suzy's Acc. Remaining value of Jack's Acc is "+str(c1.balance)+". Balance of Suzy's Acc is "+str(c3.balance)+" Thank you for using our bank.")
elif (transAccTo == 4):
c4.balance = c4.balance + transMoney
print ("You have transfered money from Jack's Acc to Craig's Acc. Remaining value of Jack's Acc is "+str(c1.balance)+". Balance of Craig's Acc is "+str(c4.balance)+" Thank you for using our bank.")
elif (transAccTo == 5):
c5.balance = c5.balance + transMoney
print ("You have transfered money from Jack's Acc to Vic's Acc. Remaining value of Jack's Acc is "+str(c1.balance)+". Balance of Vic's Acc is "+str(c5.balance)+" Thank you for using our bank.")
else:
print ("You have input the wrong account to transfer money. Please check it again.")
I have created python code like this for my ATM machine code-transfering. Since I am not skilled at python, I created code one by one. (I have further codes that are to transfer from other users to transfer to another users.)
I have identified five users at the beginning of the code.
class Customer:
def __init__ (self, name, birth, address, hkid, balance):
self.name = name
self.birth = birth
self.address = address
self.hkid = hkid
self.balance = balance
#Assigning elements that are going to be in an array.
c1 = Customer ("Jack", "Jan, 10th, 1996", "430 Davis Ct., San Francisco",
"M8875895", 40000)
c2 = Customer ("Smith", "March 24th, 1997", "3-5 Tai Koo Shing, Hong Kong", "M3133242", 600)
c3 = Customer ("Suzy", "May 5th, 1995", "32 Clearwater Bay Ave. Hong Kong", "M8378644", 100000)
c4 = Customer ("Craig", "May 24th, 1993", "700 Powell Street, San Francisco", "M2314565", 70000)
c5 = Customer ("Vic", "September 21st, 1992", "1210 Freud Street, New York", "M1234569", 3400)
#Appending customer information into the array
CustomerList = []
CustomerList.append (c1)
CustomerList.append (c2)
CustomerList.append (c3)
CustomerList.append (c4)
CustomerList.append (c5)
But the problem is that I will have to add more users into the array that I've made. And based on transfer code that I've made, I can't do anything with new users that will be created.
Is there a way for me to simplifying transfering code using Customer ... so that I can add more new users into the array and do some banking works with those newly created users?