Missing parts of Code - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Missing parts of Code (/thread-41816.html) |
Missing parts of Code - Felipe1991_GVT - Mar-22-2024 def distribute_notes(withdrawal_amount): # List of available notes in the ATM available_notes_at_atm = [200, 100, 50, 20, 10] # List with the value of the note and the available quantity total_available_notes_per_note = [(200, 500), (100, 2000), (50, 5000), (20, 10000), (10, 10000)] used_notes = [] # Check if the withdrawal is valid (minimum of 10 dollars and multiple of 10) if withdrawal_amount < 10 or withdrawal_amount % 10 != 0: return "Invalid withdrawal amount. The withdrawal must be at least 10 dollars and multiple of 10." # Limit 10 dollars notes for withdrawals below 100 dollars if withdrawal_amount < 100: max_10_dollars_notes = 3 else: max_10_dollars_notes = 0 for note_value, available_quantity in total_available_notes_per_note: # Limit the use of 10 dollars notes if note_value == 10 and len(used_notes) >= max_10_dollars_notes: continue while withdrawal_amount >= note_value and available_quantity > 0: used_notes.append(note_value) withdrawal_amount -= note_value available_quantity -= 1 if withdrawal_amount != 0: return "It's not possible to withdraw this amount with the available notes." else: return used_notes response = 'yes' balance = 2500 while response == 'yes': withdrawal_amount = int(input("How much do you want to withdraw? ")) if withdrawal_amount <= balance: balance = balance - withdrawal_amount print(f"Current balance is: {balance}") else: print("Unauthorized operation") response = input("Do you want to perform another operation? [yes/no] ") RE: Missing parts of Code - deanhystad - Mar-22-2024 Do you have a question? RE: Missing parts of Code - Felipe1991_GVT - Mar-22-2024 (Mar-22-2024, 05:06 PM)deanhystad Wrote: Do you have a question? Yes, as I run the code the "used_notes = []" on line 6 is not changing, I want to make a simulation of withdrawn using the least amount of notes taking in consideration the balance, I just don't know how to write properly RE: Missing parts of Code - deanhystad - Mar-22-2024 I don't think any of this should be in the function: # List of available notes in the ATM available_notes_at_atm = [200, 100, 50, 20, 10] # List with the value of the note and the available quantity total_available_notes_per_note = [(200, 500), (100, 2000), (50, 5000), (20, 10000), (10, 10000)] used_notes = [] |