-
Notifications
You must be signed in to change notification settings - Fork 0
/
PureBanking.py
120 lines (92 loc) · 4.51 KB
/
PureBanking.py
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
#!/usr/bin/python3
# To Create New Account
def create_new_account():
print ("Your Account Number :", account_number)
if ((len(account_number)) == max_account_number_length):
if (account_number not in account_holders):
account_holders[account_number] = 0.0
print ("Your Account is successfully opened!\nAccount Balance is: ",account_holders[account_number])
return
else:
print ("\nAccount Number '{0}' Already Exist!!".format(account_number))
return
else:
print("\nYou New Account Number is not valid!!\nPlease try again!")
return
# Deposit into Account
def deposit():
print ("\n** Deposit **\n")
print ("\nYou Account Number is: ", account_number)
try:
deposit_amount = float(input("\nEnter the Amount to deposit: "))
account_holders[account_number] += deposit_amount
print ("\nYour New Account Balance: ", account_holders[account_number])
return
except:
print ("Your Transaction is Failed!!\nTry again after some time.")
print ("\nYour New Account Balance: ", account_holders[account_number])
return
# Withdraw from Account
def withdraw():
print ("\n\n** Withdraw **\n")
print ("You Account Number is: ", account_number)
try:
withdraw_amount = float(input("\nEnter the Amount to withdraw: "))
if (withdraw_amount > account_holders[account_number]):
print("\nSorry, You are out of limit!!")
return
else:
account_holders[account_number] -= withdraw_amount
print ("\nYour New Account Balance: ", account_holders[account_number])
return
except ValueError:
print ("Your Transaction is Failed!!\nTry again after some time.")
print ("\nYour New Account Balance: ", account_holders[account_number])
return
# ****** Main Function ******
account_holders = {'0001' : 10.0, '0002' : 20.0, '0003' : 30.0} # Account Number : Account Balance
max_account_number_length = 4 # Change to increase the length of account number
while True: # condition is always true
#print ("\n** For testing purpose **\n")
#print ("\nExisting Account Numbers : ", account_holders.keys())
#print ("\nAccount Balance : ", account_holders.values())
choose = int(input("\nEnter the Choice:\n1. Deposit \n2. Withdraw \n3. To Create New Account \n4. Exit \n")) # Make Choice
if (choose == 1):
account_number = (input("\nEnter {0} digit Account Number: ".format(max_account_number_length)))
if ((len(account_number)) == max_account_number_length):
if (account_number in account_holders):
print ("\nYour Current Account Balance: ", account_holders[account_number])
deposit() #call function deposit
else:
print("\nYou Account Number is not valid!!\nPlease check and retry!")
new_option = int(input("\n** Sub Menu **\nEnter the Choice:\n1. Open New Account \n2. Exit to Main Menu and Retry\n"))
if (new_option == 1):
create_new_account()
else:
break
else:
print("\nYou Account Number is not valid!!\nPlease check and retry!")
continue
elif (choose == 2):
account_number = (input("Enter {0} digit Account Number: ".format(max_account_number_length)))
if ((len(account_number)) == max_account_number_length):
if (account_number in account_holders):
print ("\nYour Current Account Balance: ", account_holders[account_number])
withdraw() #call function withdraw
else:
print("\nYou Account Number is not valid!!\nPlease check and retry!")
break
else:
print("\nYou Account Number is not valid!!\nPlease check and retry!")
continue
elif (choose == 3):
account_number = (input("\nEnter {0} digit New Account Number: ".format(max_account_number_length)))
if ((len(account_number)) == max_account_number_length):
create_new_account()
else:
print("\nYou New Account Number is not valid!!\nPlease try again!")
continue
else:
print("Thank you for Banking with us!\nHave a Nice Day!!")
input()
break