مشاركة حلول: عمل أكثر من atm


#1

مرحباً جميعاً

المهمة المطلوبة

بإمكانك الإطلاع على المهمة المطلوبة من هنا

كيفية كتابة الأكواد في المنتدى


#2

السلام عليكم
إليكم مشاركتي

class ATM:
    def __init__(self, bank_name, balance):
        self.bank_bame = bank_name
        self.balance = balance

    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:
            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

            result = self.balance - request

        return result


balance1 = 500
balance2 = 1000

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

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

atm2.withdraw(500)
atm2.withdraw(250)


#3
class ATM:

	def __init__(self,balance,bank_name):
		self.balance = balance
		self.bank_name = bank_name


	def print_information(self):
		print("Welcome to "+ self.bank_name)
		print("current balance: " + str(self.balance))


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

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

	

	def withdraw(self, request):

		if self.balance > 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")

				else:
					request -= 5
					print("give 5")
		return self.balance			
	 
		    
	
balance1 = 500
balance2 = 1000

atm1 = ATM(balance1, "islamy bank")
atm2 = ATM(balance2, "baraka bank")

atm1.print_information()
atm1.check_balance(300)
atm1.withdraw(300)

atm1.print_information()
atm1.check_balance(250)
atm1.withdraw(250)


atm2.print_information()
atm2.check_balance(500)
atm2.withdraw(500)

atm2.print_information()
atm2.check_balance(455)
atm2.withdraw(455)


#4

السلام عليكم اسف على التأخير بسبب انشغالي بفرحي

class ATM:
	def __init__(self, balance, bank_name):
		self.balance = balance
		self.bank_name = bank_name
	def withdraw(self, request):
		print("welcome to ", self.bank_name)
		print("balance = ", self.balance)
		if request <= self.balance:
			if request > 0 :
				self.balance -= request
				while request > 0 :
					if request >= 100 :
						request -= 100
						print("give 100")

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

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

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

					else:
						print("give",request)
						break
			else:
				print("please try again")
		else:
			print("not enough money")
		return self.balance

atm1 = ATM(500, "Jordan Bank")
atm1.withdraw(700)
atm1.withdraw(300)

atm2 = ATM(1000, "Islamic Bank")
atm2.withdraw(500)
atm2.withdraw(250)

#5

سلام استاذي هذا حلي المتواضع :wink:

class ATM:
    def __init__(self, balance, bank_name):
        self.balance = balance
        self.bank_name = bank_name

    def withdraw(self, request):

        print("the name of bank is :",self.bank_name)
        print("the 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.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

balance1=500
balance2=1000
atm1=ATM(balance1,"smart_bank")
atm2=ATM(balance2,"baraka_bank")
result = atm1.withdraw(300
print("the rest of balance for smart bank are",atm1.balance)
atm2.withdraw(500)
print("the rest of balance for baraka bank are",atm2.balance)


#6

عمل رائع,

بإمكانك التخلص من المتغير result لأن الوصول للرصيد ممكن عبر atm1.balance مباشرة… انتقلي للخطوة التالية :wink:
:


#7

وهو كذالك لقد قمت بالتغيير في نفس الكود