Advertisement
IMustRemainUnknown

Withdraw and Deposit Challenge 2

Nov 24th, 2023
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.48 KB | Source Code | 0 0
  1. Max = 10000  # Max withdraw allowed is 10000
  2. deposit_input = input("Enter the number of denominations to be deposited: ")
  3.  
  4. # deposit part
  5. splitter = deposit_input.split(",")
  6. deposit = [int(d) for d in splitter]
  7.  
  8. # conversion of the user input deposit
  9. d_20, d_50, d_100, d_200, d_500, d_1000 = deposit
  10.  
  11. total = (d_20 * 20) + (d_50 * 50) + (d_100 * 100) + (d_200 * 200) + (d_500 * 500) + (d_1000 * 1000)
  12.  
  13. print("Your starting balance is:", total, "pesos")
  14.  
  15. withdrawing = True
  16.  
  17. while withdrawing:
  18.     condition = True
  19.  
  20.     d_20, d_50, d_100, d_200, d_500, d_1000 = deposit
  21.  
  22.     total = (d_20 * 20) + (d_50 * 50) + (d_100 * 100) + (d_200 * 200) + (d_500 * 500) + (d_1000 * 1000)
  23.  
  24.     while condition:
  25.         proceed = True
  26.         wit = input("Enter the amount you want to withdraw: ")
  27.         withd = int(wit)
  28.         reversed_num = str(withd)[::-1]
  29.         digits = [int(digit) for digit in str(reversed_num)]
  30.  
  31.         withdcheck = withd
  32.  
  33.         if 0 < digits[0] < 10 or digits[1] == 1:
  34.             if withdcheck > Max:
  35.                 print("The maximum total withdrawal amount is reached or exceeds 10,000 pesos.")
  36.             else:
  37.                 print("The withdraw amount is invalid.")
  38.         else:
  39.             if 0 < withdcheck <= Max:
  40.                 while withdcheck > 0:
  41.                     if d_1000 > 0 and withdcheck >= 1000:
  42.                         dispensedcheck = withdcheck // 1000
  43.                         withdcheck -= dispensedcheck * 1000
  44.                         d_1000 -= dispensedcheck
  45.  
  46.                     elif d_500 > 0 and withdcheck >= 500:
  47.                         dispensedcheck = withdcheck // 500
  48.                         withdcheck -= dispensedcheck * 500
  49.                         d_500 -= dispensedcheck
  50.  
  51.                     elif d_200 > 0 and withdcheck >= 200:
  52.                         dispensedcheck = withdcheck // 200
  53.                         withdcheck -= dispensedcheck * 200
  54.                         d_200 -= dispensedcheck
  55.  
  56.                     elif d_100 > 0 and withdcheck >= 100:
  57.                         dispensedcheck = withdcheck // 100
  58.                         withdcheck -= dispensedcheck * 100
  59.                         d_100 -= dispensedcheck
  60.  
  61.                     elif d_50 > 0 and withdcheck >= 50:
  62.                         dispensedcheck = withdcheck // 50
  63.                         withdcheck -= dispensedcheck * 50
  64.                         d_50 -= dispensedcheck
  65.  
  66.                     elif d_20 > 0 and withdcheck >= 20:
  67.                         dispensedcheck = withdcheck // 20
  68.                         withdcheck -= dispensedcheck * 20
  69.                         d_20 -= dispensedcheck
  70.  
  71.                     else:
  72.                         proceed = False
  73.                         print("The ATM can no longer dispense the withdraw amount due to lack of bank notes.")
  74.                         break
  75.  
  76.                 if proceed:
  77.                     while withd > 0:
  78.  
  79.                         if d_1000 > 0 and withd >= 1000:
  80.                             dispensed = withd // 1000
  81.                             withd -= dispensed * 1000
  82.                             d_1000 -= dispensed
  83.                             print("Dispensing", dispensed, "1000-peso banknotes.")
  84.  
  85.                         elif d_500 > 0 and withd >= 500:
  86.                             dispensed = withd // 500
  87.                             withd -= dispensed * 500
  88.                             d_500 -= dispensed
  89.                             print("Dispensing", dispensed, "500-peso banknotes.")
  90.  
  91.                         elif d_200 > 0 and withd >= 200:
  92.                             dispensed = withd // 200
  93.                             withd -= dispensed * 200
  94.                             d_200 -= dispensed
  95.  
  96.                             print("Dispensing", dispensed, "200-peso banknotes.")
  97.  
  98.                         elif d_100 > 0 and withd >= 100:
  99.                             dispensed = withd // 100
  100.                             withd -= dispensed * 100
  101.                             d_100 -= dispensed
  102.  
  103.                             print("Dispensing", dispensed, "100-peso banknotes.")
  104.  
  105.                         elif d_50 > 0 and withd >= 50:
  106.                             dispensed = withd // 50
  107.                             withd -= dispensed * 50
  108.                             d_50 -= dispensed
  109.  
  110.                             print("Dispensing", dispensed, "50-peso banknotes.")
  111.  
  112.                         elif d_20 > 0 and withd >= 20:
  113.                             dispensed = withd // 20
  114.                             withd -= dispensed * 20
  115.                             d_20 -= dispensed
  116.                             print("Dispensing", dispensed, "20-peso banknotes.")
  117.  
  118.                         else:
  119.                             print("The ATM can no longer dispense the withdraw amount due to lack of bank notes.")
  120.                             break
  121.  
  122.                     balance = total - int(wit)
  123.                     total = balance  # Update the total to the new balance
  124.                     print(f"THANK YOU FOR BANKING!\nAvailable balance: {total} pesos")
  125.  
  126.  
  127.             else:
  128.                 print(
  129.                     "Invalid withdrawal amount. The maximum withdrawal amount is 10,000 pesos. Please enter a valid amount.")
  130.  
  131.         decision = input("Do you want to withdraw again? (Y/N) ")
  132.  
  133.         if decision == "Y":
  134.             continue
  135.         else:
  136.             condition = False
  137.             print(f"THANK YOU FOR BANKING!\nAvailable balance: {total} pesos")
  138.             break
  139.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement