ATM with function


#1

I’m sorry to change codes but this is my method to understund things :blush:
Here I’m just added the input, it looks more logical if customer wants to choose his request by itself…
but the problem is how to use the last balance to do a new request.

some suggestion Sir @YaserAlnajjar

I tried to do in the last:

balance -= balance

but I will find balance = 0 by this way

request = raw_input("put your request : ")
request = int(request)

def give(request, amount):
   print ("give " + str(amount))
   return request - amount

def do_request(balance, request):
   balance -= request

   amounts = [100, 50, 10, 5, 1]
   while (request > 0):
       for amount in amounts:
           if (request >= amount):
               if amount == 1:
                   amount = request
               request = give(request, amount)
               break
   return balance

def withdraw(balance, request):
   if (not isinstance(balance, int) or not isinstance(request, int)):
       print ("Inputs must be numbers")
   elif (request <= 0):
       print ("Request must be greater than 0")
   elif (request > balance):
       print ("You don't have enough funds")
   else:
       return do_request(balance, request)

balance = 500
balance = withdraw(balance, request)

print ("Your balance : " + str(balance))


#2

you already returned the new balance so you can simply say

balance = 500

balance = withdraw(balance, 200)
balance = withdraw(balance, 300)

cuz you set the balance each time you call withdraw function


#3

OK :ok_hand: Thank you sir @YaserAlnajjar,


#4

I’m learning flask , Please Sir @YaserAlnajjar Did you have the course about what you did in the forum of OMAC ?
I have the link of your correction of the forum’s workshop by Django,
But I want to read your lessons about framework.


#5

Here are the old lessons: https://drive.google.com/open?id=1x2xaBphfQvfeR286RdQzsOCsbfhv7jmZ

If you find anything missing, please lemme know :wink:


#6

Wonderful :heart_eyes: sure Sir @YaserAlnajjar :ok_hand: