مشاركة حلول: الاحتفاظ بعمليات السحب

اضيفو اين ؟

2 Likes

يمكنك اضافتها في الدالة withdraw هكذا

def withdraw (self,request):
        result = self.balance
        print("welcome to",self.bank_name)
1 Like
class ATM:
	def __init__(self  , balance ,bank_name ):
		self.balance =balance
		self.bank_name =bank_name
		self.write_req =[]

	def withdraw(self ,request ):
		print("Welcome in :" , self.bank_name)
		if request >= self.balance:
			print(" go to work .... ")
		elif request < 0 :
			print("oops !? Add another zero to complete the request")
		else:
			self.write_req.append(request)
			self.balance = self.balance - request
			notes = [100 ,50 ,10 ,5]
			for note in notes:
				while request >= note:
					request -=note
					print("give :" , note)
		if request > 0:
			print("give :" , request)
		return self.balance

	def show_write_req (self):
		for show_list_req in self.write_req:
			print("This your requerts : " , show_list_req)

atm1 =ATM( 1000 ,"Saba")
atm2 =ATM( 1200 ,"INB")

atm1.withdraw(566)
atm1.withdraw(300)
atm2.withdraw(780)
atm1.show_write_req()
atm2.show_write_req()
2 Likes

حل :

class ATM:
  def __init__(self, balance, bank_name):
    self.balance = balance
    self.bank_name = bank_name
    self.withdrawals_log = []
    self.currencies=[100, 50, 10, 5,4,3,2,1]

  def greeting(self):
    print('Wellcom to {0} Bank'.format(self.bank_name))

  def get_currentbalance(self):
    print('your balance >>', self.balance)

  def check_balance(self, request):
    if not(self.balance > request) :
      print('Sorry, you are try withdraw: {0}, but Your balance just : {1}'.format(request, self.balance))
    else:
      return self.balance > request
  
  def show_withdrawlog(self):
    for item in self.withdrawals_log:
      print(item)

  def withdraw(self, request):
    self.greeting()
    self.get_currentbalance()
    if (self.check_balance(request)):
      self.withdrawals_log.append(request)
      self.balance -= request
      while request > 0:
          for coin in self.currencies:
              while request >= coin:
                  print('give', coin)
                  request-=coin


balance1 = 400
balance2 = 500

atm1 = ATM(balance1,"Samba")
atm2 = ATM(balance2,"ALRajhi")

atm1.withdraw(777)
atm2.withdraw(179)
atm1.withdraw(34)
atm2.withdraw(17)
atm1.withdraw(42)
atm2.withdraw(268)
atm1.withdraw(167)


print('----- log withdraw from atm1 -----')
atm1.show_withdrawlog()
print('>>>>> log withdraw from atm2 <<<<<')
atm2.show_withdrawlog()
3 Likes

عمل جميل يا attia7

1 Like

عمل جميل يا BassamMsmar.
ملاحظة بسيطة انك لم تحدد في قائمة عمليات السحب البنوك التي قمت بسحب الاموال منها.

2 Likes

اهااا فهمتك
تم التعديل

def show_write_req (self):
		for show_list_req in self.write_req:
			print("This your requerts : " , show_list_req , "From Bank :" ,self.bank_name)
2 Likes

ماشاء الله
إبدااع

2 Likes

مـهـمـة الأحـتـفـاظ بـعـمـلـيـة الـسـحـب …

class ATM:
   def __init__(self,balance,bank_name):
       self.balance=balance
       self.bank_name=bank_name
       self.withdrawals_list=[]
   
   def withdraw(self,request):
       print("Welcome to ",self.bank_name)
       print("Current balance = "+str(self.balance))
      
       if request>self.balance:
          print("More than the Available amount")
          
       elif request<0:
          print("More than zero please")
          
       else:
         
          self.balance-=request
          
          self.withdrawals_list.append(request)
          
          notes = [100, 50, 10, 5] 
          for note in notes: 
             while request >= note:
                print("give ",str(note))
                request-=note
                if request<5 and request>0:
                   print("give ",str(request))
                   request=0            
    
       return self.balance
       
   def show_withdrawals(self):
       for withdrawals in self.withdrawals_list:
          print("withdrawal amount is "+str(withdrawals))  
       
balance1=500
balance2=700

atm1=ATM(balance1,"Smart Bank")   
atm2=ATM(balance2,"Baraka Bank") 

atm1.withdraw(600)
atm1.withdraw(277)
 
atm1.show_withdrawals()


atm2.withdraw(200)
atm2.withdraw(500)

atm2.show_withdrawals()

1 Like

عمل رائع يا فاتن :+1:

1 Like

شـكـرآ :grinning:

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):
        if self.balance <= 0:
            print(f'Your balance is empty: {str(self.balance)} $')
        elif request <= 0:
            print('Please enter a valid amount')
        elif request > self.balance:
            print('Your request is upper than your balance!')
        else:
            print(f'Your {self.bank_name} balance is: {str(self.balance)} $.')
            self.balance -= request
            self.withdrawals_list.append(request)

            if request > 0 < self.balance:
                papers = [100, 50, 20, 10, 5, 2, 1]
                for paper in papers:
                    while request >= paper:
                        request -= paper
                        print(f'{paper} $')
                        
                        
            
            print(f'Your new {self.bank_name} balance is: {str(self.balance)} $.')
    
    def show_withdrawals(self):
        for i in self.withdrawals_list:
            print(i)

balance1 = 500
balance2 = 300

atm1 = ATM('AGB', balance1)
atm2 = ATM('BDL', balance2)

atm1.withdraw(440)
atm1.withdraw(17)
atm2.withdraw(140)
atm2.withdraw(170)
atm1.show_withdrawals()
atm2.show_withdrawals()


````

الناتج كما يلي..

````
Your AGB balance is: 500 $.
100 $
100 $
100 $
100 $
20 $
20 $
Your new AGB balance is: 60 $.
Your AGB balance is: 60 $.
10 $
5 $
2 $
Your new AGB balance is: 43 $.
Your BDL balance is: 300 $.
100 $
20 $
20 $
Your new BDL balance is: 160 $.
Your request is upper than your balance!
440
17
140
[Finished in 0.9s]
````
لكن ماذا لو أعمل عمليات الإحتفاظ بالسحوبات في قوائم متعددة متعلقة بالوقت واليوم؟
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):
        # allowed papers: 100, 50, 10, 5, and cents
        print("Welcome to " , self.bank_name)
        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, 1]
            for note in notes:
                while request >= note:
                    request -= note
                    print("give ", str(note))  
            print("This checkout process is complete ---")
            
    def show_withdrawals(self):
        for withdrawal in self.withdrawals_list:
            print(withdrawal)
   
balance1 = 500
balance2 = 1000
balance3 = 2000

atm1 = ATM(balance1, "Smart Bank")
atm2 = ATM(balance2, "Baraka Bank")
atm3 = ATM(balance3, "Hedra Bank")
# For example, if I withdraw the same amounts from each atms
# Then, print out the rest on each atm after all withdrawals
atms = [atm1, atm2, atm3]
req = [252, 2050, 97, 305 ]
for atm in atms:
    for r in req:
        atm.withdraw(r)
        if atm.balance > r:
            atm.balance -= r
    print("These are all withdrawals that are completed")      
    atm.show_withdrawals()
    print("The rest of the balance", ":" , atm.balance)
    print("The end of this ATM --------------- ")
2 Likes
class ATM:
   def __init__(self, bank_name, balance):
    self.bank_name = bank_name
    self.balance = balance
    self.withdrawls = []
    
   def print_information(self):
      print("Welcome to %s,Your balance is %d"%( self.bank_name, self.balance) ) 

   def valid(self , request):
      if request <= 0  |  request > self.balance:
         return False
      else:
         return True

   def withdraw(self, request):
      self.print_information()
      notes=[100,50,10,5]
      if self.valid(request):
         self.withdrawls.append(request)
         self.balance -= request
         
         for note in notes:
            if request >= note:
                while request>=note:
                    print('give',str(note))
                    request -= note
            
            elif request > 0 : 
                print('give' ,str(request))
                request=0
      else:
         print("Your request is not valid")
         
   def show_withdrawls(self):
    for x in self.withdrawls:
        print(str(x))
            
atm1=ATM("barakeh",10000)
atm1.withdraw(4054)
atm1.withdraw(500)
atm1.show_withdrawls()
1 Like

    def __init__(self, balance, bank_name):
        self.balance = balance
        self.bank_name = bank_name
        self.withdrawals_list = []

    def withdraw(self, request):

        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
            notes=[100,50,10,5]
            for note in notes:
               if request >=note:
                   request-= note
                   print('give', str(request))

               elif 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, "Samba Bank")
atm2 = ATM(balance2, "Ryadh Bank")

atm1.withdraw(700)
atm1.withdraw(300)

atm2.withdraw(500)
atm2.withdraw(250)
atm1.show_withdrawals()
atm2.show_withdrawals()
1 Like

اشارككم الحل الخاص بي

money = 500

print("your balance", money)

class ATM:
    # init
    def __init__(self,money,bank_name):
        self.money = money
        self.bank_name = bank_name
        self.withdrawals_lists = []

    # withdraw function
    def withdraw(self, request):

        print("Current Balance: ", self.money)
        result = money

        if request > self.money:
            print(" deposite more money into your account")

        elif request < 0:
            print("more than zero please")

        else:
            self.withdrawals_lists.append(request)
            result = self.money - request

            while request > 0:
                if request >= 100:
                    request = request - 100
                    print("give 100")

                elif request >= 50:
                    request = request - 50
                    print("give 50")

                elif request >= 10:
                    request = request - 10
                    print("give 10")

                elif request >= 5:
                    request = request - 5
                    print("give 5")
                elif request < 5:
                    print("give " + str(request))  # str for change the int to string
                    request = 0
                    result = self.money - request
            return result

    def showWithdraw(self):
        for withdrawla in self.withdrawals_lists:
            print(withdrawla)


# objects
customer1 = 1000
customer2 = 500
customer3 = 0

atm1 = ATM(customer1, "Ahli")
atm2 = ATM(customer2,"SABB")
atm3 = ATM(customer3, "Rajhi")
atm1.withdraw(277)
atm2.withdraw(300)
atm3.withdraw(100)
atm1.showWithdraw()
1 Like

عمل جميل يا safaa

عمل جميل يا dewofrose
ملاحظة بسيطة: يبدوا انك لما قمت بنسخ الكود نسيت ان تنسخ تعريف الكلاس في بداية الكود class ATM:

عمل جميل يا devaspirant

2 Likes
class ATM:
    def __init__(self, balance, bank_name):
        self.balance = balance
        self.bank_name = bank_name
        self.withdraws_list = []

    def give(self, request):
        if request > self.balance:
            print("Can't give you all this money !!")

        elif request < 0:
            print("More than zero plz!")

        else:
            self.withdraws_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

    def withdraw(self, request):

        print(f"your bank is {self.bank_name}")

        print("Current balance = ", self.balance)

        self.give(request)

    def show_withdraw_list(self):
        print("The withdrawals list is: ")
        for i in self.withdraws_list:
            print(i, end=", ")


atm1 = ATM(700, "baraka bank")

atm1.withdraw(185)
atm1.withdraw(200)
atm1.withdraw(65)
atm1.withdraw(93)

atm1.show_withdraw_list()

3 Likes