Atm Bill Dispenser

Today, I was given an assignment to write a program to implement an atm dispenser in the following notes: 100, 50, 20, 10, and 5. If the amount is not a multiply of 5, the atm will return a list of 0. In the code are short explanations of why I used it. # asks the customer to enter an amount of number. atm = int(input("Enter an amount in a multiple of 5: ")) # This takes in a amount parameter which is the input from the user and return an array of bills in the following orders: [$100, $50, $20, $10, $5]. def dispenser(amount): # if statement to check if number entered is divisible by 5. If not, return with 0, if yes, continue code. if atm % 5 != 0: return [0, 0, 0, 0, 0] result = [] bill_types = [100, 50, 20, 10, 5] # starts with the starting amount being divided by each number in bill_types. for each_note in bill_types: note_counts = amount // each_note result.append(note_counts) # get the remainder and overwrite the previous. amount = amount % each_note return result # The code below is what will be given back as a sentence to the customer. print(f"You entered ${atm}: {dispenser(atm)}")

August 9, 2024 · 1 min · SourFox

Finding the GCD of two numbers

In this assignment, it’ll be finding the GCD(Greatest Common Divisor). This means I need to write a program to find the GCD of two numbers. Below, I have written the program and next to the hashtags are just a sentence that’ll explain to you what each part of the code is doing. #The two variables 'num' and 'ber' will be where the inputs will be stored in. When it starts it will show '(num)a: ' and you'll have to put a number in. This goes the same for '(ber)b: ' num = int(input("a: ")) ber = int(input("b: ")) #Then once the variable has gotten their information, they will go through this: def gcd(num, ber): if ber == 0: return num else: return gcd(ber, num % ber) #And last, it'll gather their answer and print it for you as a sentence. print(f"The GCD {num}, {ber} is {gcd(num, ber)}.") That’s all today. Bye!

July 12, 2024 · 1 min · SourFox

Check if a year is a leap year

Today, I just got back to python after a few months. So when coming back, I got an assignment. My assignment was to check if a year is a leap year. In the assignment, it also gave hints. These were the hints: A leap year is a calendar year that contains an additional day (February 29th) compared to a common year. It occurs once every four year. s This is how you can determine if a year is a leap year or not: ...

May 14, 2024 · 3 min · SourFox

Assignment 2: Python Using Lists and While-Loop

I had an assignment that I was given for Python. What I have to do is to write a program in Python that asks a user to enter their favourite fruit, store each fruit in a list. At the end of the program, print out the total number of fruits, and also print all the fruits. This is what I’m expected: What is your favourite fruit? Banana (the fruit user put) What is your favourite fruit? Apple (the fruit user put) What is your favourite fruit? Orange (the fruit user put) What is your favourite fruit? (empty) (the user didn't write anything) You have 3 fruits in the basket: Banana, Apple, and Orange. So how do I do this? ...

October 7, 2023 · 5 min · SourFox