Question

In: Computer Science

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

USE PYTHON

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 

Solutions

Expert Solution

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()


Related Solutions

6.32 LAB: Exact change - functions Write a program with total change amount as an integer...
6.32 LAB: Exact change - functions Write a program with total change amount as an integer input that outputs 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, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2 dimes...
For Java 3.25 LAB: Exact change Write a program with total change amount in pennies as...
For Java 3.25 LAB: Exact change Write a program with total change amount in pennies 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 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes...
C++ 19.32 LAB: Exact change - functions Write a program with total change amount as an...
C++ 19.32 LAB: Exact change - functions Write a program with total change amount as an integer input that outputs 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, the output is: no change Ex: If the input is: 45 the output is: 1 quarter 2...
Write a program with total change amount as an integer input, and output the change using...
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 c++ please
Program in Java code Write a program with total change amount in pennies as an integer...
Program in Java code Write a program with total change amount in pennies 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. .Ex1: If the input is: 0 the output is:    No change            Ex2: If the input is:    45   the output is:   1 Quarter 2 Dimes
Write a program in pyton with total change amount as an integer input, and output the...
Write a program in pyton 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 Can you...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
4.15 LAB: Password modifier Many user-created passwords are simple and easy to guess. Write a program...
4.15 LAB: Password modifier Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string
Lab 5 a) Write a program that reads in an unsigned integer K and sums the...
Lab 5 a) Write a program that reads in an unsigned integer K and sums the first K many integers that are divisible by 7. You should output the sum on a formatted manner b)Consider the following diamond it is an 11 by 11 diamond made with * signs. Write a program that takes as input positive odd integer K (greater than or equal to three and outputs a K by K diamond made with * signs * *** *...
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT