هذه محاولتي، حاولت تنفيذ كل الشروط من بينها مبدأ SRP
class ATM:
def __init__(self, bank_name, balance):
self.bank_name = bank_name
self.balance = balance
self.paper_categories = [100, 50, 10, 5, 1]
def log_in(self):
trans = self.getTrans()
while trans != 'q':
request = int(input("ادخل مبلغ السحب: \n"))
if self.balance >= request:
self.withdraw(request)
else:
print('عذراً، لا تملك المال الكافي لسحب هذا الرصيد، يمكنك سحب مبلغ أقل')
if self.balance == 0:
print('انتهى رصيدك في حسابك')
break
trans = self.getTrans()
print('رصيدك الحالي هو:', ' $ ' + str(self.balance))
def getTrans(self):
return input("\nادخل أي حرف للسحب، (q) للخروج: \n")
def myPrint(self, paper, times):
for i in range(times):
print('give', paper, '$')
def withdraw(self, request):
if request > 0:
for i in range(len(self.paper_categories)):
if request >= self.paper_categories[i]:
numberOfThispaper = request // self.paper_categories[i]
self.balance -= (self.paper_categories[i] * numberOfThispaper)
request %= (self.paper_categories[i] * numberOfThispaper)
self.myPrint(self.paper_categories[i], numberOfThispaper)
print('تبقى لديك في حسابك: ' + str(self.balance) + '$')
else:
print('مبلغ غير صالح')
def main():
atm1 = ATM('Yemeni Tadhamon Bank', 1200)
atm2 = ATM('YK Bank', 2500)
option = int(input("""\t\t=== قم بالضغط على [1] لبنك التضامن اليمني، على [2] لبنك اليمن والكويت ، على [3] للخروج ===\n"""))
if option == 1:
atm = atm1
elif option == 2:
atm = atm2
elif option == 3:
return
else:
print('اختيار غير صحيح')
return
print("""\t\t\t\t\t\t\t\t\t\t\t=== {} ===\n""".format(atm.bank_name), '\n',
"""\t\t\t\t\t\t\t\t\t\t\t رصيدك هو: {} \n""".format(' $ ' + str(atm.balance)))
atm.log_in()
main()