forked from karan/Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Karan Goel
committed
Jul 6, 2013
1 parent
39876a5
commit d0e90fb
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |