Sunday, August 18, 2013

changeMaker.py

This is my first Python program, a re-write of the code that I put together for CS1 a couple of years ago. I've been taking my old Java assignments and rewriting them in the different languages I'm trying to teach myself.

I wrote this on Pythonista on my iPhone as I walked to get a latte on break at work. There's nothing ground-breaking here. Just me starting my baby-steps in Python.

# change maker

def main():
        print "Calculates change from a dollar."

        amount = input("Enter the amount less than one dollar.")

        amount = 100 - amount

        quarters = amount/25
        amount = amount%25
        dimes = amount/10
        amount = amount%10
        nickles = amount/5
        amount = amount%5

        print "the change due is " + str(quarters) + " quarters, " + str(dimes) + " dimes, " + str(nickles) + " nickles, and " + str(amount) + " pennies."

main()