class ATM :
def __init__(self,balance,bank_name):
self.balance=balance
self.bank_name=bank_name
self.withdrawals_list = []
def widthraw(self,request):
print(self.bank_name,'current balance=',str(self.balance),'$')
if request > self.balance:
print('the mony in the ATM not enough ')
elif request < 0:
print('please enter the mony you need')
else:
self.balance -= request
self.withdrawals_list.append(request)
notes = [100, 50, 10, 5]
for note in notes:
while request >= note:
request -= note
print("give " + str(note))
if request % 5 != 0 :
print('give ' + str(request) + ' pieces')
request = 0
print('Remaining Mony In The ATM', self.balance)
print('')
return self.balance
def show_withdrawals(self):
for withdrawal in self.withdrawals_list:
print('Withdrawaled Mony =',withdrawal)
balance1=500
balance2=1000
atm1 = ATM(balance1,"Smart_bank")
atm2 = ATM(balance2,"Taslef_bank")
atm1.widthraw(100)
atm1.widthraw(300)
atm2.widthraw(100)
atm2.widthraw(800)
atm1.show_withdrawals()
atm2.show_withdrawals()
3 Likes
عمل جميل جدا يا انس احسنت
3 Likes
عمل ممتاز رفا
3 Likes
class ATM:
def __init__(self, balance, bank_name):
self.balance = balance
self.bank_bame = bank_name
self.withdrawals_list = []
def withdraw(self, request):
notes = [100, 50, 10, 5]
# allowed papers: 100, 50, 10, 5, and cents
print("Current balance = ", self.balance)
result = self.balance
if request > self.balance:
print("Can't give you all this money !!")
elif request < 0:
print("More than zero plz!")
else:
self.withdrawals_list.append(request)
result = self.balance - request
while request > 0:
for note in notes:
while request >= note:
request -= note
print("give ", str(note))
if request < 5 and request > 0 :
print('give ' + str(request))
request = 0
return result
def show_withdrawals(self):
for withdrawal in self.withdrawals_list:
print(withdrawal)
balance1 = 500
balance2 = 1000
atm1 = ATM(balance1, "Smart Bank")
atm2 = ATM(balance2, "Baraka Bank")
atm1.withdraw(700)
atm1.withdraw(300)
atm2.withdraw(732)
atm2.withdraw(268)
2 Likes
عمل رائع أسيل
هل نحتاج لهذا الجزء:
and request > 0 :
شكرا …
نعم … لكي لا يظهر في الكشف ( give 0)
1 Like