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

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

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

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

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

  • إذا كان لديك كيبورد فرنسي, اضغط على alt gr و 7 لكتابة الرمز `

3 Likes

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

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)

1 Like
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)

2 Likes

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

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)
2 Likes

سلام استاذي هذا حلي المتواضع :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)

1 Like

عمل رائع,

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

1 Like

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

1 Like

حل عمل أكثر من atm

class ATM:

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

    def withdraw(self,request):
        papers=[100,50,10,5,2]
        while request > 0:
            if request > self.balance :
                print(" can't give you all this money !!")
                break

            for i in papers:
                while request >= i:
                    print('give' +' '+ str(i))
                    # request+=1
                    self.balance-=i
                    request-=i
                    # if not request==0 :break
            request-=1
        print('Your Balance Is'+' '+ str(self.balance))
        return self.balance

balance1 = 500
balance2 = 1000

atm1=ATM(balance1, 'Smart Bank')
atm2=ATM(balance2, 'Old Bank')
1 Like

احمد كالعادة عمل رائع (بامكانك تعديله حسب الملاحظات السابقة)، وانتقل للمهمة التالية :wink:

1 Like
# ATM class with multiple instances
class ATM:
    def __init__(self, balance, bank_name):
        self.bank_name = bank_name
        self.balance = balance

    def withdraw(self):
        # balance = 500
        print("Welcome to ", self.bank_name)
        print("Your current balance is:", self.balance, "$")

        request = input('Please, enter the required amount: ')
        request = int(request)      # To be used to validate inserted amount
        self.main_request = request      # To be used in output

        # Available banknotes 100, 50 & 20
        # To validate inserted amount that it matches available banknotes
        if request > self.balance or request <= 0:
            print('Please enter valid number')

        elif request < self.balance:
            while request >= 100:
                request -= 100
                # print(request)

            while request >= 50 and (request % 20 != 0):
                request -= 50
                # print(request)

            while request >= 20:
                request -= 20
                # print(request)

            if request != 0 and request % 20 != 0:
                print("enter valid number matzha'nesh !!")

            else:
                self.balance = self.balance - self.main_request
                print("The remaining balance is: ", self.balance)

                while self.main_request >= 100:
                    print('give 100')
                    self.main_request -= 100
                    # print("rest is: ", main_request)

                while self.main_request >= 50 and (self.main_request % 20 != 0):
                    print('give 50')
                    self.main_request -= 50
                    # print("rest is: ", main_request)

                while self.main_request >= 20:
                    print('give 20')
                    self.main_request -= 20
                    # print("rest is: ", main_request)

            print("Thank you for banking with us ... \n")


# Define instance of ATM class
atm1 = ATM(500, "Bank1")
atm2 = ATM(1000, "Bank2")

# Run withdraw function of ATM class
atm1.withdraw()
atm2.withdraw()

تم التعديل شكرا

1 Like

عمل أكثر من atm

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

	def withdraw(self,request):
	    result = self.money

	    if request > self.money:
	        print('money not enigh')
	    elif request <= 0:
	        print('plz try again')
	    else:
	        result = self.money - request
	        while request > 0:
	            if request >= 100:
	                request -= 100
	                print('100$')
	            elif request >= 50:
	                request -=50
	                print('50$')
	            elif request >= 10:
	                request -=10
	                print('10$')
	            elif request >= 5:
	                request -=5
	                print('5$')
	            elif request < 5:
	                print( str(request) + '$')
	                request = 0
	    return result

money1 = 1000
money2 = 100


atm1 = ATM(money1,'CAC bank')
atm2 = ATM(money2,'YICT bank')

print('CAC bank:'),atm1.withdraw(250)
print('CAC bank:'),atm1.withdraw(150)

print('YICT bank:'),atm2.withdraw(400)
print('YICT bank:'),atm2.withdraw(300)
1 Like

عمل ممتاز يا علي :+1: :+1:

1 Like
class ATM:

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



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


atm1 = ATM(1000, 'Faisal Bank')
atm2 = ATM(700,'HSBC Bank')


atm1.withdraw(355)
atm1.withdraw(800)


atm2.withdraw(500)
atm2.withdraw(50)

1 Like

عمل متقن يا احمد :+1:

لكن بما ان مستواك متقدم نوعا ما، ابحث في الحلول بالاعلى عن طريقة لتنظيف الاكواد باستعمال for loop مع while :wink:

Look at this my teacher

class ATM():
    def __init__(self, balance, name):
        self.balance = balance
        self.name = name
    def print_bank_name(self):
        print("Welcome to {} Bank".format(self.name))

    def withdraw(self, request):
        requested=0
        if   request > self.balance:
            print("Can't give you all this money !!")
            
        elif request < 0:
            print("More than zero plz!")
            
        else:
            requested = request
            
            print("[*] Request for {}$".format(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")
                else:
                    print("give {}".format(request))
                    print("[*] Request for {}$ Done".format(request))
                    print("")
                    break
        return self.balance-requested

balance1 = 500
balance2 = 1000

atm1 = ATM(balance1, "Barak")
atm2 = ATM(balance2, "AGB")
atm1.print_bank_name()
atm1.withdraw(477)
atm1.print_bank_name()
atm2.withdraw(566)
1 Like
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("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(balance1, "Smart Bank")
atm2 = ATM(balance2, "Baraka Bank")

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

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

عمل رائع يا مصعب :+1:

جرب أن تكتب بعد هذه الأسطر:

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

قم بكتابة السطر print(atm1.balance) ولاحظ النتيجة… هل هي سليمة ؟

1 Like

نعم ولاحظ نتيجة التشغيل

500
welcome to  Smart Bank
Current balance =  500
Can't give you all this money !!
welcome to  Smart Bank
Current balance =  500
give 100
give 100
give 100
welcome to  Baraka Bank
Current balance =  1000
give 100
give 100
give 100
give 100
give 100
welcome to  Baraka Bank
Current balance =  1000
give 100
give 100
give 50

Process finished with exit code 0
1 Like

هو لا يعمل كما هو المفترض منه أن يقوم به :smile:

هذا هو الكود الذي جربته، أضفت له السطر print('koko', atm1.balance):

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("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(balance1, "Smart Bank")
atm2 = ATM(balance2, "Baraka Bank")

atm1.withdraw(700)
atm1.withdraw(300)
print('koko', atm1.balance)

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

وهذه النتيجة:

Current balance =  500
give 100
give 100
give 100
koko 500

استعملت الكلمة koko لجعلها واضحة من بين بقية الأسطر.

1 Like