class ATM:
def __init__(self, balance, bank_name):
self.balance = balance
self.bank_name = bank_name
self.withdraw_list = []
def withdraw(self, request):
print("Bank Name is:", self.bank_name)
print("balance is ", self.balance)
if request > self.balance:
print("Can't give you all this money !!")
elif request < 0:
print("More than zero plz!")
else:
self.withdraw_list.append(request)
self.balance = self.balance - request
while request > 0:
if request >= 100:
request -= 100
print("give 100")
elif request >= 50:
request -= 50
print("give 50")
elif request >= 10:
request -= 10
print("give 10")
elif request >= 5:
request -= 5
print("give 5")
elif request < 5:
print("give " + str(request))
request = 0
return self.balance
def show_withdraw_list(self):
for i in self.withdraw_list:
print(i)
atm1 = ATM(1000, 'Faisal Bank')
atm2 = ATM(700, 'HSBC Bank')
atm1.withdraw(355)
atm1.withdraw(800)
atm1.show_withdraw_list()
atm2.withdraw(500)
atm2.withdraw(50)
atm2.show_withdraw_list()
1 Like
class ATM:
def __init__(self, money, bank_name):
self.money = money
self.bank_name = bank_name
self.withdrawals_list = []
def withdraw(self,request):
result = self.money
if request > self.money:
print('money not enigh')
elif request <= 0:
print('plz try again')
else:
self.withdrawals_list.append(request)
self.money -= request
notes = [100, 50, 10, 5]
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)
money1 = 1000
money2 = 1000
atm1 = ATM(money1,'CAC bank')
atm2 = ATM(money2,'YICT bank')
print('CAC bank:'),atm1.withdraw(250)
print('CAC bank:'),atm1.withdraw(153)
print('YICT bank:'),atm2.withdraw(400)
print('YICT bank:'),atm2.withdraw(313)
print('withdrawal:')
atm1.show_withdrawals()
2 Likes
هذه محاولتي
class ATM():
def __init__(self, balance, name):
self.balance = balance
self.name = name
self.withdrawals_list = []
def print_bank_name(self):
print("Welcome to {} Bank".format(self.name))
def show_withdrawals(self):
print("=== This is All with withdrawals on {} Bank ===".format(self.name))
for i in self.withdrawals_list:
print(i)
def withdraw(self, request):
self.print_bank_name()
requested=0
if request > self.balance:
print("Can't give you all this money !!")
elif request < 0:
print("More than zero plz!")
else:
allowed_paper = [100, 50, 10, 5]
requested = request
self.withdrawals_list.append(request)
print("[*] Request for {}$".format(request))
for paper in allowed_paper:
while requested >= paper:
requested -= paper
print("give {}".format(paper))
if requested != 0:
print("give {}".format(requested))
print("[*] Request for {}$ Done".format(request))
print("")
return self.balance-requested
balance1 = 500
balance2 = 1000
atm1 = ATM(balance1, "Barak")
atm2 = ATM(balance2, "AGB")
atm1.withdraw(188)
atm1.withdraw(200)
atm2.withdraw(566)
atm2.withdraw(275)
atm1.show_withdrawals()
atm2.show_withdrawals()
1 Like
عمل رائع جداً يا كمال
بالنسبة للسطر:
print("=== This is All with withdrawals on {} Bank ===".format(self.name))
بدلاً من format تستطيع استعمال f بهذا الشكل:
print(f"=== This is All with withdrawals on {self.name} Bank ===")
1 Like
هذا رائع ^^
شكرا استاذ ياسر
1 Like
على الرحب والسعة
1 Like
هل هناك خطأ يأصدقاء
class ATM:
def __init__(self, balance, bank_name):
self.balance = balance
self.bank_bame = bank_name
self.withdrawals_list = []
def withdraw(self, request):
print('welcome to', self.bank_bame)
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)
self.balance -= request
notes = [100, 50, 10, 5]
for note in notes:
while request >= note:
request -= note
print("give ", str(note))
if request < 5:
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(500)
atm2.withdraw(250)
atm2.show_withdrawals()
2 Likes
كل شيء ممتاز في هذا الكود يا مصعب
1 Like
السلام عليكم، هذا الكود السابق مع تعديله ليحتفظ بعمليات السحب.
##########################################################
# Simulation of ATM in Python #
# allowed papers: 100, 50, 10, 5, and rest of request #
##########################################################
balance1 = 2562
balance2 = 3000
cont = True
class ATM:
def __init__(self, balance, bank_name):
self.balance = balance
self.bank_name = bank_name
self.withdrawal_list = []
def withdrawal(self):
print("\n\n\n")
request = int(input("Enter the amount you want to withdraw :"))
if (request > 0) and (request <= self.balance):
self.withdrawal_list.append(request)
notes = [100, 50, 10, 5]
for note in notes:
while request >= note:
print("give " + str(note))
self.balance -= note
request -= note
print("give " + str(request))
self.balance -= request
request -= request
self.balance -= request
# print ("your current balance is " + str(balance) )
else:
print('Sorry, we can\'t proceed with your request. \nThe amount number is incorrect or you don\'t '
'have enough balance for your request')
return self.balance
def show_withdrawals(self):
for withdrawal in self.withdrawal_list:
print("ATM Cash withdrawal Debit :" + str(withdrawal))
atm1 = ATM(balance1, "EAST BANK")
atm2 = ATM(balance2, "WEST BANK")
while cont:
print("\n\n")
print("***********************************************")
print("** WELCOME TO YOUR BANKS **")
print("***********************************************")
print("** DESIG.: " + atm1.bank_name + ". Current balance =" + str(atm1.balance) + " **")
print("***********************************************")
print("** DESIG.: " + atm2.bank_name + ". Current balance =" + str(atm2.balance) + " **")
print("***********************************************")
print("\n\n\n\n")
answer = int(input("Please select : 1=" + atm1.bank_name + " Withdrawal, 2=" + atm2.bank_name + " Withdrawal, 3=Exit "))
if answer == 1:
atm1.withdrawal()
atm1.show_withdrawals()
if answer == 2:
atm2.withdrawal()
atm2.show_withdrawals()
if answer == 3:
cont = False
print("Thank you for your visit")
وهذه النتيجة بعد تجربة الكود:
***********************************************
** WELCOME TO YOUR BANKS **
***********************************************
** DESIG.: EAST BANK. Current balance =258 **
***********************************************
** DESIG.: WEST BANK. Current balance =3000 **
***********************************************
Please select : 1=EAST BANK Withdrawal, 2=WEST BANK Withdrawal, 3=Exit 1
Enter the amount you want to withdraw :228
give 100
give 100
give 10
give 10
give 5
give 3
ATM Cash withdrawal Debit :228
***********************************************
** WELCOME TO YOUR BANKS **
***********************************************
** DESIG.: EAST BANK. Current balance =30 **
***********************************************
** DESIG.: WEST BANK. Current balance =3000 **
***********************************************
Please select : 1=EAST BANK Withdrawal, 2=WEST BANK Withdrawal, 3=Exit 1
Enter the amount you want to withdraw :30
give 10
give 10
give 10
give 0
ATM Cash withdrawal Debit :228
ATM Cash withdrawal Debit :30
***********************************************
** WELCOME TO YOUR BANKS **
***********************************************
** DESIG.: EAST BANK. Current balance =0 **
***********************************************
** DESIG.: WEST BANK. Current balance =3000 **
***********************************************
Please select : 1=EAST BANK Withdrawal, 2=WEST BANK Withdrawal, 3=Exit 3
Thank you for your visit
Process finished with exit code 0
2 Likes
عمل ممتاز يا ابراهيم
2 Likes
شكرا جزيلا استاذي على توجيهاتكم ونصائحكم القيمة
1 Like
على الرحب والسعة
class ATM:
def __init__(self, bank_name, balance):
self.bank_name = bank_name
self.balance = balance
self.withdrawals_list = []
def withdraw(self, request):
print('current balance = ', self.balance)
if self.balance < request :
print ('cant give you all the money !!')
elif request < 0 :
print ('more then zero plz !!')
else:
self.withdrawals_list.append(request)
self.balance -= request
notes = [100, 50, 10, 5]
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 self.balance
def show_withdrawals(self):
for withdrawal in self.withdrawals_list :
print(withdrawal)
balance1 = 1000
balance2 = 755
atm1 = ATM('savings bank', balance1 )
atm2 = ATM('central bank', balance2 )
print('savings bank :') , atm1.withdraw(700)
print('savings bank :') , atm1.withdraw(300)
print('central bank :') , atm2.withdraw(544)
print('central bank :') , atm2.withdraw(133)
print('withdrawal :')
atm1.show_withdrawals()
atm2.show_withdrawals()
3 Likes
جميل جدا ArijTrabelsi.
2 Likes
شكرا
1 Like
class atm :
def __init__(self,balance,bank_name):
self.balance= balance
self.bank_name=bank_name
self.withdrawals_list = []
def withdraw (self,request):
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
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))
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,"barka")
atm1.withdraw(277)
atm1.withdraw(10)
atm2.withdraw(288)
atm2.withdraw(200)
atm2.show_withdrawals()
هل هذا صحيح ؟
2 Likes
عمل جميل يا محمود
ملاحظة بسيطة: لم تحدد البنك الذي سحبت منه الاموال، كما انك طبعت فقط العمليات التي جرت على البنك الثاني دون الاول.
2 Likes
ممكن توضحلى ب الاكود
2 Likes
لو ننفذ البرنامج كما هو تكون النتيجة هكذا:
give 100
give 100
give 50
give 10
give 10
give 5
give 2
give 10
give 100
give 100
give 50
give 10
give 10
give 10
give 5
give 3
give 100
give 100
288
200
لكن لو نضيف له هذا السطر البرمجي:
print('welcome to', self.bank_name)
عندما ننفذ تكون النتيجة هكذا:
welcome to smart bank
give 100
give 100
give 50
give 10
give 10
give 5
give 2
welcome to smart bank
give 10
welcome to barka
give 100
give 100
give 50
give 10
give 10
give 10
give 5
give 3
welcome to barka
give 100
give 100
288
200
بالتوفيق
1 Like