Question

USE PYTHON Please!!! 4.15 LAB: Exact change Write a program with total change amount as an...

USE PYTHON Please!!!

4.15 LAB: Exact change

Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies.

Ex: If the input is:

0 

(or less than 0), the output is:

No change 

Ex: If the input is:

45

the output is:

1 Quarter
2 Dimes 

Homework Answers

Answer #1
def exactChange(userTotal):
    if (userTotal <= 0):
        return None
    else:
        numDollars = userTotal // 100
        userTotal %= 100

        numQuarters = userTotal // 25
        userTotal %= 25

        numDimes = userTotal // 10
        userTotal %= 10

        numNickels = userTotal // 5
        numPennies = userTotal % 5

        return (numDollars, numQuarters, numDimes, numNickels, numPennies)


# Testing
def main():
    n = int(input())
    res = exactChange(n)
    if(res == None):
        print("No change")
    else:
        numDollars = res[0]
        numQuarters = res[1]
        numDimes = res[2]
        numNickels = res[3]
        numPennies = res[4]

        if numDollars > 0:
            if numDollars == 1:
                print('%d Dollar' % numDollars)
            else:
                print('%d Dollars' % numDollars)

        if numQuarters > 0:
            if numQuarters == 1:
                print('%d Quarter' % numQuarters)
            else:
                print('%d Quarters' % numQuarters)

        if numDimes > 0:
            if numDimes == 1:
                print('%d Dime' % numDimes)
            else:
                print('%d Dimes' % numDimes)

        if numNickels > 0:
            if numNickels == 1:
                print('%d Nickel' % numNickels)
            else:
                print('%d Nickels' % numNickels)

        if numPennies > 0:
            if numPennies == 1:
                print('%d Penny' % numPennies)
            else:
                print('%d Pennies' % numPennies)

main()

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Create a Change application that prompts the user for an amount less than $1.00 and then...
Create a Change application that prompts the user for an amount less than $1.00 and then displays the minimum number of coins necessary to make the change. The change can be made up of quarters, dimes, nickels, and pennies. The application output should look similar to: Enter the change in cents: 212 The minimum number of coins is: Quarters: 8 Dimes: 1 Nickels 0 Pennies: 2 Must be coded in Java please
Write a C program that prints 1 if there is an exact change using nickels (5...
Write a C program that prints 1 if there is an exact change using nickels (5 cents), dimes (10 cents), quarters (25 cents), loonies ($1), toonies ($2) and bills and 0 if there is none. For example, if the change is $7.25 it prints 1 because, the change would be 7 loonies($1), two dimes and a nickel.  
program has to be written in X86 processor assy language. Write a program that find the...
program has to be written in X86 processor assy language. Write a program that find the minimum number of coins that can represent an amount of money under $1. The amount of money is a random number between 0 and 99 (cents). The randomRange procedure is used to get a random number. Review the sample code in lab4.asm and run it to see how randomRange works. Each time randomRange is called, it creates a random number between 0 and the...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a...
6.31 LAB: Count characters - methods ----- javascript please Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z Today is Monday the output is: 0 Ex: If the input is: n It's a sunny day the output is: 2 Case matters. n is different than N. Ex:...
7.6 LAB: Exception handling to detect input String vs. Integer The given program reads a list...
7.6 LAB: Exception handling to detect input String vs. Integer The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a String rather than an Integer. At FIXME in the code, add a try/catch statement to catch java.util.InputMismatchException, and output 0 for the age. Ex: If the input is: Lee 18 Lua...
USE PYTHON. Notice that the output needs to be as it is required. 4.18 LAB*: Program:...
USE PYTHON. Notice that the output needs to be as it is required. 4.18 LAB*: Program: Automobile service invoice (1) Output a menu of automotive services and the corresponding cost of each service. (2 pts) Ex: Davy's auto shop services Oil change -- $35 Tire rotation -- $19 Car wash -- $7 Car wax -- $12 (2) Prompt the user for two services from the menu. (2 pts) Ex: Select first service: Oil change Select second service: Car wax (3)...
c++ 19.36 LAB: Output values below an amount - functions Write a program that first gets...
c++ 19.36 LAB: Output values below an amount - functions Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, and output all integers less than or equal to that value. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75 The 5 indicates that there are five integers...
Python Programming 1. Write the following Python expressions in mathematical notation. a. dm = m *...
Python Programming 1. Write the following Python expressions in mathematical notation. a. dm = m * (sqrt(1 + v / c) / sqrt(1 - v / c) - 1) b. volume = pi * r * r * h c. volume = 4 * pi * r ** 3 / 3 d. z = sqrt(x * x + y * y) 2. What are the values of the following expressions? In each line, assume that s = "Hello" t =...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT