CSC111 Teller Machine Program

From dftwiki3
Revision as of 17:25, 8 February 2015 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- <br /> <source lang="python"> # tellerMachine1.py # D. Thiebaut # A simple example of a teller machine program. # The user enters the amount to withdraw, and the #...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 16:25, 8 February 2015 (EST)



# tellerMachine1.py
# D. Thiebaut
# A simple example of a teller machine program.
# The user enters the amount to withdraw, and the
# program figures out the number of bills to give out.

def main():
    # get the amount to withdraw from the user.
    amount = int( input( "How much money do you need? " ) )


    # compute the number of bills in various denominations
    no20s = amount // 20     # integer number of $20-bills

    leftOver = amount % 20   # remainder of amount divided by 20

    no10s = leftOver // 10   # integer number of $10-bills in
                             # left-over

    leftOver = leftOver % 10 # left-over of the left-over once we take
                             # the $10 bills away

    no5s = leftOver // 5     # integer number of $5-bills

    leftOver = leftOver % 5  # left-over of the left-over after we take
                             # the $5 bills away

    no1s = leftOver

    # output the results for the user, in # bills given out by the machine.
    print()
    print( no20s, "$20-bill(s)" )
    print( no10s, "$10-bill(s)" )
    print( no5s, "$5-bill(s)" )
    print( no1s, "$1-bill(s)" )
    print()


main()