Skip to content

Commit

Permalink
Change Return Program done
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Goel committed Jul 6, 2013
1 parent 39876a5 commit d0e90fb
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Numbers/change.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Change Return Program - The user enters a cost and
# then the amount of money given. The program will figure
# out the change and the number of quarters, dimes, nickels,
# pennies needed for the change.

if __name__ == '__main__':
cost = input("What's the cost in dollars? ")
given = input("What's the amount of dollars given? ")

change = given - cost

print "\n"
if change < 0:
print "Please ask for $%.2f more from the customer." % (-change) # double negation
else:
print "The change is $%.2f." % change

q = 0 # 0.25
d = 0 # 0.10
n = 0 # 0.05
p = 0 # 0.01

change = int(change * 100) # let's talk about cents

if change >= 25:
q = int(change / 25)
change = change % 25
if change >= 10:
d = int(change / 10)
change = change % 10
if change >= 5:
n = int(change / 5)
change = change % 5
if change >= 1:
p = change # rest all change is in pennies

print "Give the following change to the customer:"
print "Quarters: %d\tDimes: %d\tNickels: %d\tPennies: %d" \
% (q, d, n, p)

# DEBUG
# print "Total change per the number of coins is %.2f" % \
# ((q * .25) + (d * .10) + (n * 0.05) + (p * 0.01))

0 comments on commit d0e90fb

Please sign in to comment.