|
| 1 | +import pickle |
| 2 | +import os |
| 3 | +class Account: |
| 4 | + def __init__(self,id=10000000): |
| 5 | + self.type=input('what type of Account you Want to open? S(min 5000) or C(min 10000) :').upper() |
| 6 | + self.name=input('Enter name: ') |
| 7 | + self.id=id |
| 8 | + while True: |
| 9 | + self.amount=int(input('Enter Amount: ')) |
| 10 | + if self.type in ('s','S'): |
| 11 | + if self.amount<5000: |
| 12 | + print('Enter Amount Again') |
| 13 | + continue |
| 14 | + else: |
| 15 | + break |
| 16 | + if self.type in ('c','C'): |
| 17 | + if self.amount<10000: |
| 18 | + print('Enter Amount Again') |
| 19 | + continue |
| 20 | + else: |
| 21 | + break |
| 22 | + def display(self): |
| 23 | + print('{:<20}{:<20}{:<20}{:<20}'.format(self.id,self.name,self.type,self.amount)) |
| 24 | +#create account |
| 25 | +def CreateAccount(): |
| 26 | + try: |
| 27 | + file=open('keshav.bin','rb') |
| 28 | + while True: |
| 29 | + p=pickle.load(file) |
| 30 | + except FileNotFoundError as e: |
| 31 | + file1=open('keshav.bin','ab') |
| 32 | + s=Account() |
| 33 | + pickle.dump(s,file1) |
| 34 | + file1.close() |
| 35 | + except EOFError as e: |
| 36 | + file1=open('keshav.bin','ab') |
| 37 | + p.id+=1 |
| 38 | + print(p.id) |
| 39 | + s=Account(p.id) |
| 40 | + pickle.dump(s,file1) |
| 41 | + file1.close() |
| 42 | +#display function |
| 43 | +def DisplayFile(): |
| 44 | + file=open('keshav.bin','rb') |
| 45 | + print('{:<20}{:<20}{:<20}{:<20}'.format('id','name','type','amount')) |
| 46 | + try: |
| 47 | + while True: |
| 48 | + p=pickle.load(file) |
| 49 | + p.display() |
| 50 | + except Exception as e: |
| 51 | + print(e) |
| 52 | + else: |
| 53 | + file.close() |
| 54 | +#deposit money |
| 55 | +def Deposit(): |
| 56 | + file=open('keshav.bin','rb+') |
| 57 | + file1=open('temp.bin','wb') |
| 58 | + n=int(input('enter id ex. 10000000: ')) |
| 59 | + money=int(input('enter money to deposit: ')) |
| 60 | + try: |
| 61 | + while True: |
| 62 | + p=pickle.load(file) |
| 63 | + if p.id==n: |
| 64 | + p.amount+=money |
| 65 | + pickle.dump(p,file1) |
| 66 | + except: |
| 67 | + file.close() |
| 68 | + file1.close() |
| 69 | + finally: |
| 70 | + os.remove('keshav.bin') |
| 71 | + os.rename('temp.bin','keshav.bin') |
| 72 | + |
| 73 | +#withdraw money |
| 74 | +def Withdraw(): |
| 75 | + def main_money(): |
| 76 | + def avail_money(): |
| 77 | + money=int(input('enter money in multiple of 100 200 500 2000: ')) |
| 78 | + l=[100,200,500,2000] |
| 79 | + for i in l: |
| 80 | + if money%i==0: |
| 81 | + return money |
| 82 | + else: |
| 83 | + continue |
| 84 | + else: |
| 85 | + print("u cant withdraw money ") |
| 86 | + return False |
| 87 | + while True: |
| 88 | + r=avail_money() |
| 89 | + if r==False: |
| 90 | + print('failed') |
| 91 | + continue |
| 92 | + else: |
| 93 | + return r |
| 94 | + |
| 95 | + def load_money(file,file1): |
| 96 | + while True: |
| 97 | + p=pickle.load(file) |
| 98 | + if p.id==n: |
| 99 | + while True: |
| 100 | + money=main_money() |
| 101 | + if p.amount<money: |
| 102 | + print("insufficient balance!") |
| 103 | + continue |
| 104 | + else: |
| 105 | + if p.type=='C': |
| 106 | + if p.amount-money>=10000: |
| 107 | + p.amount-=money |
| 108 | + print('process completed successfully !') |
| 109 | + break |
| 110 | + else: |
| 111 | + print("\t can't withdraw money","\n\t your current account limit is 10000","\n\t you can withraw max: ",p.amount-10000) |
| 112 | + continue |
| 113 | + if p.type=='S': |
| 114 | + if p.amount-money>=5000: |
| 115 | + p.amount-=money |
| 116 | + print('process completed successfully !') |
| 117 | + break |
| 118 | + else: |
| 119 | + print("\tcan't withdraw","\n\t your current account limit is 5000","\n\t you can withraw max: ",p.amount-5000) |
| 120 | + continue |
| 121 | + pickle.dump(p,file1) |
| 122 | + file=open('keshav.bin','rb+') |
| 123 | + file1=open('temp.bin','wb') |
| 124 | + n=int(input('enter id ex. 10000000: ')) |
| 125 | + try: |
| 126 | + load_money(file,file1) |
| 127 | + except: |
| 128 | + file.close() |
| 129 | + file1.close() |
| 130 | + finally: |
| 131 | + os.remove('keshav.bin') |
| 132 | + os.rename('temp.bin','keshav.bin') |
| 133 | +#update your account |
| 134 | +def Update(): |
| 135 | + file=open('keshav.bin','rb+') |
| 136 | + file1=open('temp.bin','wb') |
| 137 | + n=int(input('enter id ex. 10000000: ')) |
| 138 | + name=input('Enter new name: ') |
| 139 | + #type=input('Enter type of account: ').upper() |
| 140 | + try: |
| 141 | + while True: |
| 142 | + p=pickle.load(file) |
| 143 | + if p.id==n: |
| 144 | + p.name=name |
| 145 | + pickle.dump(p,file1) |
| 146 | + except: |
| 147 | + file.close() |
| 148 | + file1.close() |
| 149 | + finally: |
| 150 | + os.remove('keshav.bin') |
| 151 | + os.rename('temp.bin','keshav.bin') |
| 152 | +#search your account |
| 153 | +def Search(): |
| 154 | + file=open('keshav.bin','rb') |
| 155 | + n=int(input('enter id ex. 10000000: ')) |
| 156 | + try: |
| 157 | + while True: |
| 158 | + p=pickle.load(file) |
| 159 | + if p.id==n: |
| 160 | + print(' {:*>35} {:*<35}'.format('start detail of account: ',p.name)) |
| 161 | + print('id: ',p.id,'\nname: ',p.name,'\ntotal balance: ',p.amount,'\ntype: ',p.type) |
| 162 | + print(' {:*>35} {:*<35}'.format(' end detail of account: ',p.name)) |
| 163 | + break |
| 164 | + except: |
| 165 | + file.close() |
| 166 | + else: |
| 167 | + file.close() |
| 168 | +# |
| 169 | +print("{:*^70}".format(' Banking Management System '),end='\n'*3) |
| 170 | +def Choise(): |
| 171 | + print('What Do You Wanna Do?') |
| 172 | + print('1.Create Account') |
| 173 | + print('2.View all Accounts') |
| 174 | + print('3.Deposit') |
| 175 | + print('4.Withdraw') |
| 176 | + print('5.Update') |
| 177 | + print('6.Search') |
| 178 | + print('7.Exit') |
| 179 | + return int(input('Enter your choise here: ')) |
| 180 | +while True: |
| 181 | + i=Choise() |
| 182 | + if i==1: |
| 183 | + CreateAccount() |
| 184 | + if i==2: |
| 185 | + DisplayFile() |
| 186 | + if i==3: |
| 187 | + Deposit() |
| 188 | + if i==4: |
| 189 | + Withdraw() |
| 190 | + if i==5: |
| 191 | + Update() |
| 192 | + if i==6: |
| 193 | + Search() |
| 194 | + if i==7: |
| 195 | + break |
0 commit comments