Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Missing parts of Code
#1
Question 
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] ")
deanhystad write Mar-22-2024, 05:05 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Do you have a question?
Felipe1991_GVT likes this post
Reply
#3
(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
Reply
#4
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 = []
Felipe1991_GVT likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to expand and collapse individual parts of the code in Atom Lora 2 1,167 Oct-06-2022, 07:32 AM
Last Post: Lora
  QR code data missing in some of my QR codes Pedroski55 6 3,612 Jan-26-2021, 04:38 AM
Last Post: Pedroski55
  Having a hard time combining two parts of code. Coozeki 6 3,103 May-10-2020, 06:50 AM
Last Post: Coozeki
  I am trying to make a Colour Wars game, "Winning code" missing Ondrejoda 0 2,287 Feb-18-2018, 11:06 AM
Last Post: Ondrejoda
  looking for sweeter code to compare parts of a list Skaperen 7 4,907 Jun-20-2017, 12:16 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020