Specs: Ubuntu 13.04, Python 3.3.1
General Background: total beginner to Python;
Question-specific background: I'm exhausted trying to solve this problem, and I'm aware that, besides its instructional value for learning Python, this problem is boring and does not in any way make this world a better place :-( So I'd be even more grateful if you could share some guidance on this exhausting problem. But really don't want to waste your time if you are not interested in this kind of problems.
What I intended to do: "Calculate the number of basic American coins given a value less than 1 dollar. A penny is worth 1 cent, a nickel is worth 5 cents, a dime is worth 10 cents,
and a quarter is worth 25 cents. It takes 100 cents to make 1 dollar. So given an amount less than 1 dollar (if using floats, convert to integers for this exercise), calculate the number of each type of coin necessary to achieve the amount, maximizing the number of larger denomination coins. For example, given $0.76, or 76 cents, the correct output would be "3 quarters and 1 penny." Output such as "76 pennies" and "2 quarters, 2 dimes, 1 nickel, and 1 penny" are not acceptable."
What I was able to come up with:
penny = 1
nickel = 5
dime = 10
quarter = 25
i = input("Please enter an amount no more than 1 dollar(in cents): ")
i = int(i)
if i > 100:
print ("Please enter an amount equal or less than 100. ")
elif i >= quarter:
quarter_n = i % quarter
i = i - quarter * quarter_n
if i >= dime:
dime_n = i % dime
i = i - dime * dime_n
if i >= nickel:
nickel_n = i % nickel
i = i - nickel * nickel_n
if i >= penny:
penny_n = i % penny
print (quarter_n,"quarters,",dime_n,"dimes",nickel_n,"nickels",penny_n,"pennies")
else:
if i >= penny:
penny_n = i % penny
print (quarter_n,"quarters,",dime_n,"dimes",penny_n,"pennies")
else:
if i >= nickel:
nickel_n = i % nickel
i = i - nickel * nickel_n
if i >= penny:
penny_n = i % penny
print (quarter_n,"quarters,",nickel_n,"nickels",penny_n,"pennies")
else:
if i >= penny:
penny_n = i % penny
print (quarter_n,"quarters,",penny_n,"pennies")
else:
if i >= dime:
dime_n = i % dime
i = i - dime * dime_n
if i >= nickel:
nickel_n = i % nickel
i = i - nickel * nickel_n
if i >= penny:
penny_n = i % penny
print (dime_n,"dimes",nickel_n,"nickels",penny_n,"pennies")
else:
if i >= penny:
penny_n = i % penny
print (dime_n,"dimes",penny_n,"pennies")
else:
if i >= nickel:
nickel_n = i % nickel
i = i - nickel * nickel_n
if i >= penny:
penny_n = i % penny
print (nickel_n,"nickels",penny_n,"pennies")
else:
if i >= penny:
penny_n = i % penny
print (penny_n,"pennies")
This solution, though the best I could come up with, does not work as expected when fed with actual input numbers. And I'm unable to figure out why. Besides, I know that even from sheer size of the code that something is wrong. I searched for similar questions but the closest I got was one that dealt with very difficult math which I couldn't understand.
My question: I know I can't ask for a complete solution because that's down to me to figure it out. I'll appreciate either a) general pointer on the correct line of thinking b) critiques to my current code/line of thinking so that I might be able to improve it.
Thank you for taking the time, even just reading this!
I think your solution may actually be working if you do a "find and replace" for all the mod operators %, switching in integer division //.
Say you have 76 cents and want to find the number of quarters. Using 76 % 25 results in 1 whereas 76 // 25 is 3.
With regard to the code, you should probably be thinking in terms of iterating over the possible coin values rather than a huge if, elif mess.
Try something like this. The only part that may need some explaining is using divmod but its really just a tuple of the integer division, modulo result. You can use that to get the number of coins and the new amount, respectively.
def coins_given(amount):
coins = [(25, 'quarter'), (10, 'dime'), (5, 'nickel'), (1, 'penny')]
answer = {}
for coin_value, coin_name in coins:
if amount >= coin_value:
number_coin, amount = divmod(amount, coin_value)
answer[coin_name] = number_coin
return answer
print coins_given(76)
# {'quarter': 3, 'penny': 1}
i think your algorithm is too complicated,
you don't need all the elifs and the elses
just check with and if and then modidy the remaining amount until you get to zero
something like this
penny = 1
nickel = 5
dime = 10
quarter = 25
q = 0
d = 0
n = 0
p = 0
i = input("Please enter an amount no more than 1 dollar(in cents): ")
i = int(i)
if i>=25:
q = i/quarter
i %= quarter
if i>=10:
d = i/dime
i%=dime
if i>=5:
n = i/nickel
i %= nickel
if i>0:
p = i/penny
i = 0
print "The coins are %i quarters, %i dimes, %i nickels and %i pennys." %(q , d, n, p)
>>>
Please enter an amount no more than 1 dollar(in cents): 99
The coins are 3 quarters, 2 dimes, 0 nickels and 4 pennys.
>>>
Please enter an amount no more than 1 dollar(in cents): 76
The coins are 3 quarters, 0 dimes, 0 nickels and 1 pennys.
dime=10
nickel=5
penny=1
quarter=25
def change(cents):
changeIs = ""
qs = cents/quarter
cents %= quarter
if qs > 0 :
changeIs += str(qs) + " quarter(s)"
ds = cents/dime
cents %= dime
if ds > 0 :
changeIs += " " + str(ds) + " dime(s)"
ns = cents/nickel
cents %= nickel
if ns > 0 :
changeIs += " " + str(ns) + " nickel(s)"
if cents > 0 :
changeIs += " " + str(cents) + " cent(s)"
return changeIs
if __name__ == '__main__':
cents=int(raw_input("Enter the change: "))
print change(cents)
Related
Why is this code creating an infinite loop? I would think this should be an appropriate solution for this type of problem. For example, if the price was $5 and you paid $5.47, the program would print:
Quarters: 1
Dimes: 2
Nickels: 0
Pennies: 2
However, an infinite loop occurs and I'm not sure why. Anyone know the reason?
price = round(float(input("Enter the price: ")), 2)
print price
paid = round(float(input("Enter the amount paid: ")), 2)
print paid
change = round(float(paid - price), 2)
print change
quarters = 0
dimes = 0
nickels = 0
pennies = 0
while change > 0.00:
print change
if change >= .25:
change = change - .25
quarters += 1
continue
elif change >= .1:
change = change - .1
dimes += 1
continue
elif change >= .05:
change = change - .05
nickels += 1
elif change >= .01:
change = change - .01
pennies += 1
print "Quarters: " + str(quarters)
print "Dimes: " + str(dimes)
print "Nickels: " + str(nickels)
print "Pennies: " + str(pennies)
Rather than dealing with loops, I would suggest just subtracing off the change that you already gathered, prioritizing larger coins.
price = float(input("Enter the price: "))
paid = float(input("Enter the amount paid: "))
change = paid - price
if change < 0:
raise ValueError('Not enough paid')
quarters = change // 0.25
dimes = (change - (0.25 * quarters)) // 0.10
nickels = (change - (0.25 * quarters) - (0.10 * dimes)) // 0.05
pennies = 100 * (change - (0.25 * quarters) - (0.10 * dimes) - (0.05 * nickels))
print("Quarters: {:.0f}".format(quarters))
print("Dimes: {:.0f}".format(dimes))
print("Nickels: {:.0f}".format(nickels))
print("Pennies: {:.0f}".format(pennies))
There's one minor bug in the code which causes the program to only work correctly if price and amount paid are interchanged (e.g. price = 2, paid = 1). But that is not the issue causing the infinite loop.
Your code creates an infinite loop for e.g. the following arguments:
price: 5.6
paid: 5.4
The reason for the infinite loop can be seen from your own print output:
0.009999999999999275
0.009999999999999275
0.009999999999999275
0.009999999999999275
0.009999999999999275
0.009999999999999275
0.009999999999999275
...
Since change < 0.01, no if clause applies and thus the loop is never left.
How could you solve the problem more robustly?
Here's a sketch
from math import floor
change = paid - price
quarters = int(floor(change / 0.25))
change -= quarters * 0.25
dimes = int(floor(change / 0.1))
change -= dimes * 0.1
nickels = int(floor(change / 0.05))
change -= nickels * 0.05
pennies = int(floor(change / 0.01))
change -= pennies * 0.01
remaining = change
print("Quarters:", quarters)
print("Dimes:", dimes)
print("Nickels:", nickels)
print("Pennies:", pennies)
Personally I would also condense this into a loop over the coin type:
increments = {"quarter":0.25, "dimes": 0.1, "nickels": 0.05, "pennies": 0.01}
change_parts = {}
for inc_name, inc in increments.items():
amount = int(floor(change / inc))
print(inc_name, inc, amount)
change -= amount * inc
change_parts[inc_name] = amount
for inc_name, amount in change_parts.items():
print(inc_name + ":", amount)
I have an assignment where I have to prompt the user for cost of a product and amount paid, I have to output change in pennies, dimes, quarters, $1, $5, $20, $50, and $100, for example: The cost of the item is $19.99 and the client pays with a $50 bill. The change to be provided is 1 $20 bill, one $10 bill, and one penny.
I am confused how to get an output like that though, any help would be greatly appreciated, heres what I have so far
cost = float(input('Cost: '))
amount_paid = float(input('Amount paid: '))
penny = 0.01
dime = 0.10
quarter = 0.25
dollar_1 = 1.00
dollar_5 = 5.00
dollar_10 = 10.00
dollar_20 = 20.00
dollar_50 = 50.00
dollar_100 = 100.00
change = cost - amount_paid
if amount_paid < cost:
print('Error')
I dont know what to do next
A common misstep here is to use floats. You should instead convert everything to the smallest whole unit (a cent) and use integer math. Floating point math is...fuzzy.
currencies = {"penny": 1,
"nickel": 5,
"dime": 10,
"quarter": 25,
"dollar": 1_00,
"five": 5_00,
"ten": 10_00,
"twenty": 20_00,
"fifty": 50_00,
"hundred": 100_00}
# never seen that numeric notation before? It's safe to embed underscores
# in numerical literals! It's often used for large numbers in place of
# commas, but it makes sense here in place of a period.
Then you should only need to define a dictionary for the result, and use divmod to find how many of the denomination can fit in the amount left due.
change_due = {}
for denomination, amt in reversed(currencies.items()):
if amt < amt_due:
d, m = divmod(amt_due, amt)
change_due[denomination] = d
amt_due = m
welcome to stackoverflow! I wrote the code for you and this is how it works. Basically it sees each currency and uses integer division // to see how many integers can fit in. It then subtracts that amount from the remaining change and the process continues. Please ask if you don't understand something, or if you think there is an error.
Code:
cost = float(input('Cost: '))
amount_paid = float(input('Amount paid: '))
penny = 0.01
dime = 0.10
quarter = 0.25
dollar_1 = 1.00
dollar_5 = 5.00
dollar_10 = 10.00
dollar_20 = 20.00
dollar_50 = 50.00
dollar_100 = 100.00
changeTypes = {dollar_100:0,dollar_50:0,dollar_20:0,dollar_10:0,dollar_5:0,dollar_1:0,quarter:0,dime:0,penny:0}
change = amount_paid-cost
if amount_paid < cost:
print('Error: InsufficientFunds')
for changeType in changeTypes:
numAmount = max(0,change//changeType)
change-=numAmount*changeType
changeTypes[changeType] = int(numAmount)
print(changeTypes)
P.S you should make this a function, it shouldn't be too hard.
You could do this good with dictionaries, but without using still there are many ways to go about this, options are endless, heres one idea
def get_bills(change, value):
if change//value > 0:
bills = change//value
change -= bills * value
return bills, change
else:
return 0, change
cost = float(input('Cost: '))
paid = float(input('Amount Paid: '))
while paid < cost:
paid = float(input('Amount Paid: '))
change = paid - cost
hundreds, change, = get_bills(change, 100)
fifties, change, = get_bills(change, 50)
twenties, change = get_bills(change, 20)
tens, change = get_bills(change, 10)
fives, change = get_bills(change, 5)
ones, change = get_bills(change, 1)
quarters, change = get_bills(change, .25)
dimes, change = get_bills(change, .1)
nickels, change = get_bills(change, .05)
pennies = round(change * 100)
print(f"Hundreds: {hundreds}, Fifties: {fifties}, Twenties: {twenties}," +
f" Tens: {tens}, Fives: {fives}, Ones: {ones}, Quarters: {quarters}," +
f" Dimes: {dimes}, Nickels: {nickels}, Pennies: " +
f"{pennies}")
bill = float(input())
paid = float(input())
Available = {100.0:0,50.0:0,20.0:0,10.0:0,5.0:0,1.0:0,0.25:0,0.10:0,0.01:0}
due = paid-bill
for change in sorted(Available,reverse = True):
amt= max(0,due//change)
due-=amt*change
Available[change] = int(amt)
print(Available)
I know this is a late response but maybe it can help someone.
Below is a code for doing exactly what you want. The program iterates through the notes available from largest to smallest and calculates how many times the current note may be used to deduct from the remaining change to be given.
Finally returning a list containing the notes used to reach the sum required.
# Available notes for change
notes = [500, 200, 100, 50, 20, 10]
def change_notes(change, notes):
notes_out = []
for note in notes:
print(f"current note is {note}")
sleep(1)
while change > 0 and note <= change:
if change - note >= 0:
change -= note
notes_out.append(note)
print(f"change is {change}")
sleep(1)
if change == 0:
break
return notes_out
Here is a basic math problem. I want to calculate least amount of banknotes to be paid.
Here is my code and working well.
total_payment = int(input("Please enter the total amount: "))
Dollar50 = int(total_payment // 50)
remaining_money = total_payment % 50
Dollar20 = int(remaining_money // 20)
remaining_money = remaining_money % 20
Dollar10 = int(remaining_money // 10)
remaining_money = remaining_money % 10
Dollar5 = int(remaining_money // 5)
remaining_money = remaining_money % 5
Dollar1 = int(remaining_money // 1)
print("We need {0} 50 dollar.".format(Dollar50))
print("We need {0} 20 dollar.".format(Dollar20))
print("We need {0} 10 dollar.".format(Dollar10))
print("We need {0} 5 dollar.".format(Dollar5))
print("We need {0} 1 dollar.".format(Dollar1))
But i want to print only if that type of banknote is used. For example if total amount is 101 dollar than program prints
We need 2 50 dollar.
We need 0 20 dollar.
We need 0 10 dollar.
We need 0 5 dollar.
We need 1 1 dollar.
But i dont want to print the ones with 0 value. I only want it to print
We need 2 50 dollar.
We need 1 1 dollar.
This was an example of my struggle. I can not code this kind of loops or conditions. Thank you very much for any help.
Instead of writing an if statement for all of these just zip them together and use a for loop:
counts = [Dollar50, Dollar20, Dollar10, Dollar5, Dollar1]
ammounts = [50, 20, 10, 5, 1]
for i, j in zip(counts, ammounts):
if i:
print("We need {} {} dollar.".format(i, j))
All you need is an if condition.
As an exercise, you should try to write DRY code. Using loops and lists would look like this
face_values = [50, 20, 10, 5, 1]
amounts = [0]*5
remaining_money = int(input("Please enter the total amount: "))
# While you have money left, calculate the next most 'dollar_value' you can use
i = 0 # This is an index over the 'dollars' list
while remaining_money > 0:
d = face_values[i]
amounts[i] = remaining_money // d
remaining_money %= d
i+=1
denomination = "dollar bill"
denomination_plural = denomination + "s"
# Iterate both values and amounts together and print them
for val, amount in zip(face_values, amounts):
if amount == 1: # Filter out any non-positive amounts so you don't show them
print("We need {} {} {}.".format(val, amount, denomination))
else if amount > 1:
print("We need {} {} {}.".format(val, amount, denomination_plural))
Use
if Dollar50:
print("We need {0} 50 dollar.".format(Dollar50))
if the value is 0, it won't print anything.
Speaking simplistically, just add an if statement around each print statement checking for a 0.
if Dollar50 != 0:
print("We need {0} 50 dollar.".format(Dollar50))
if Dollar20 != 0:
print("We need {0} 20 dollar.".format(Dollar20))
Continue that for each item.
I'm using Python, and I am trying to convert a certain amount of money in cents to its equivalent in quarters, nickels, dimes and pennies.
This is what I have so far, but I see the problem is that I don't know how to take the remainder from the quarters and break it down into dimes, nickels and pennies. I'm new to this and just having a hard time. I'm not asking for someone to solve the problem, just point out what I did wrong (and maybe what I need to do to fix it).
# Convert some money to an appropriate collection of cents
penny = 1
nickel = 5
dime = 10
quarter = 25
quarters = 0
dimes = 0
nickels = 0
pennys = 0
cents = int(input("Please enter an amount of money you have in cents: "))
if cents >= 25:
quarters = cents / quarter
cents % quarter
if cents >= 10:
dimes = cents/dime
cents % dime
if cents >= 5:
nickels = cents /nickel
cents % nickel
if cents > 0:
pennys = cents / penny
cents = 0
print ("The coins are: quarters", quarters,\
",dimes", dimes, ",nickels", nickels, ", and pennys.", pennys)
Using divmod, it's just three lines:
quarters, cents = divmod(cents, 25)
dimes, cents = divmod(cents, 10)
nickels, pennies = divmod(cents, 5)
There are two operations that you need here: integer division and modulo.
Integer division A / B asks a simple question: How many times will B fit into A cleanly (without having to break B into decimal pieces)? 2 fits into 8 cleanly 4 times. 2 fits into 9 cleanly 4 times as well.
Modulo A % B asks the same question but gives the flip-side of the answer: Given that A goes into B cleanly some number of times, what's left over? 2 goes into 8 cleanly 4 times with nothing left over, so 2 % 8 is 0. 2 goes into 9 cleanly 4 times but 1 is left over, so 2 % 9 is 1.
I'll give you another example, and let you make the transition from that to your problem. Let's say I'm given a number of seconds, and I need to convert it to days, hours, minutes and seconds.
total_seconds = 345169
# Specify conversion between seconds and minutes, hours and days
seconds_per_minute = 60
seconds_per_hour = 3600 # (60 * 60)
seconds_per_day = 86400 # (3600 * 24)
# First, we pull out the day-sized chunks of seconds from the total
# number of seconds
days = total_seconds / seconds_per_day
# days = total_seconds // seconds_per_day # Python3
# Then we use the modulo (or remainder) operation to get the number of
# seconds left over after removing the day-sized chunks
seconds_left_over = total_seconds % seconds_per_day
# Next we pull out the hour-sized chunks of seconds from the number of
# seconds left over from removing the day-sized chunks
hours = seconds_left_over / seconds_per_hour
# hours = seconds // seconds_per_hour # Python3
# Use modulo to find out how many seconds are left after pulling out
# hours
seconds_left_over = seconds_left_over % seconds_per_hour
# Pull out the minute-sized chunks
minutes = seconds_left_over / seconds_per_minute
# minutes = seconds_left_over // seconds_per_minute # Python3
# Find out how many seconds are left
seconds_left_over = seconds_left_over % seconds_per_minute
# Because we've removed all the days, hours and minutes, all we have
# left over are seconds
seconds = seconds_left_over
Was struggling with this yesterday evening. True, you need division and modulo. Not the most Pythonic way, but it works for any amount, when you restrict the amount of dollars you can input into the vending machine to $5.00. This question has been asked around and has been continually ignored. Maybe because it is homeworksque... Anyway....
def vending_machine_change():
cost = float(input("Enter cost of item: "))
change= 5.00-cost
dollars = int(change)
quarters_change= float("%.2f" % ((change-dollars)))
quarters =int(quarters_change/0.25)
dime_change= float("%.2f" % (quarters_change%0.25))
dimes=int(dime_change/0.10)
nickel_change = float("%.2f" % (dime_change%0.10))
nickels= int(nickel_change/0.05)
pennys = int(nickel_change*100)
print("Change amount: " + str((dollars)) + ' Dollars, ' + str((quarters)) + ' Quarters, '+ str((dimes)) + ' Dimes, '+ str((nickels)) + ' Nickels, '+ str((pennys)) + ' Pennies' )
pass
Updated my new code at the bottom of the page as an answer.
So for my CS 170 class, we have to make a program that has user input for less than $10 and change is returned in the least amount of coins, no bills or 50 cent pieces. For the most part the program does well except when you run into a x.x0
e.g.:
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Amount due:
7.80
Amount in return
2.20.
Quaters in return 8.
Dimes in return 0.
Nickels in return 4.
>>>
the program completely skips over the dimes section and straight to nickels providing 4 as a solution when the least amount should be 8 quarters, 2 dimes and end. Also I'm not really skilled in loops too much, but I know this would be possible and a lot shorter code, and cleaning up the code advice would be nice as well. Thanks for any help!
# optional.py
# Calculating the least amount of change in return for a $10 bill.
## amount due
due = input("Amount due:\n ")
## if amount is more than 10, exit program
if due > 10.00:
print "Please enter a number lower then 10.00."
exit()
## if amount is less than 0, exit program
if due < 0:
print "Please enter a number greater than 0.00."
exit()
## subtract amount from 10
else:
change = 10.00 - due
print "Amount in return\n %0.2f." % change
## if amount is 0, no change
if change == 0:
print "No change in return."
## passes expression if previous not met
pass
elif change >= .25:
## setting q, dividing change by .25
q = change / .25
## maaking q an integer
quaters = int(q)
print "Quaters in return %r." % quaters
## subtracting quaters from chane
change = change - (quaters *.25)
if change < .10:
pass
elif change >= .10 <= .24:
d = change * .1
dimes = int(d)
print "Dimes in return %r." % dimes
change = change - (dimes * .1)
if change < .05:
pass
elif change >=.05 <=.09:
n = change / .05
nickels = int(n)
print "Nickels in return %r." % nickels
change = change - (nickels * .05)
if change == .01:
pennies = change / .01
print "Pennies in return %r." % pennies
elif change >=.01 <=.04:
p = change / .01
print "Pennies in return %0.0f." % p
There are a few changes you could make to clean up this code, and one of them might fix your problem. First, pass does absolutely nothing. It is usually used as a placeholder for a loop or function that will be filled in later. Also, the conditions of your elif statements are mutually exclusive with the if statements they follow, so
if change == 0:
print "No change in return."
## passes expression if previous not met
pass
elif change >= .25:
## setting q, dividing change by .25
q = change / .25
## maaking q an integer
quaters = int(q)
print "Quaters in return %r." % quaters
## subtracting quaters from chane
change = change - (quaters *.25)
can be rewritten as
if change >= .25:
## setting q, dividing change by .25
q = change / .25
## making q an integer
quaters = int(q)
print "Quaters in return %r." % quaters
## subtracting quaters from change
change = change - (quaters *.25)
for each if/elif statement. Also, in the statement
if change >=.01 <=.04:
you are testing whether
change >= .01 and .01 <= .04
To make it do what you want, the statement should be rewritten as
if .01 <= change <= .04
In addition, you are using floating point numbers, which often lead to rounding errors. To avoid these errors, I would suggest either representing your money as an integer number of cents and multiply all of the numbers in your problem by 100 or use something with fixed point numbers like python's decimal module.
This is not doing what you expect:
elif change >= .10 <= .24:
It looks like you intend something like:
elif change >= .10 and change <= .24:
or Python also supports:
elif .10 <= change <= .24:
However, you will next run into floating point rounding problems of various kinds. I suggest you first convert the input number to an integer number of cents, and perform all your calculations in cents. Avoid floating point numbers when dealing with money.
So I got it worked out in a better format with cleaner print code. Thanks for the help guys!
If anyone wants to know the difference between the 2 codes, it's getting it out of floating point like the others suggested and converting what is needed to integers, multiplying the integers by the specific amount, say a quarter, and then subtracting int * coin/bill from the change. Worked out well. I tried experimenting with a for statement, but that didn't turn out too well since I don't know a lot about it yet either. Until next time...
Again thanks guys!
Here's the finished code for anyone wondering about it:
import sys
due = input("Please enter the amount due on the item(s):\n ")
# if over $10, exit
if due > 10:
print "Please enter an amount lower then 10."
sys.exit(1)
## if under/equal 0, exit
if due <= 0:
print "Please enter an amount greater than 0."
sys.exit(2)
## 10 - due = change, converts change into cents by * by 100 (100 pennies per dollar)
else :
change = 1000 - (due * 100)
## if change is 0, done
if change == 0:
print "No change in return!"
## if not 0 makes change2 for amount in return
else:
change2 = change / 100
print "Amount in return:\n $%.2f." % change2
## if change > 500, subract 500 and you get 1 $5 bill
if 500.0 <= change:
bill_5 = change / 500
b5 = int(bill_5)
change = change - 500
## if change is over 100, change divided by 100 and subtracted from change for quaters
if 100.0 <= change:
dollars = change / 100
dollar = int(dollars)
change = change - (dollar * 100)
if 25 <= change < 100:
quaters = change / 25
quater = int(quaters)
change = change - (quater * 25)
if 10 <= change <= 24:
dimes = change / 10
dime = int(dimes)
change = change - (dime * 10)
if 5 <= change < 10:
nickels = change / 5
nickel = int(nickels)
change = change - (nickel * 5)
if 0 < change < 5:
pennies = change / 1
penny = int(pennies)
change = change - (penny * 1)
print "Change in return:\n $5:%i\n $1:%i\n Quaters:%i\n Dimes:%i\n Nickels:%i\n Pennies:%i " % (
b5, dollar, quater, dime, nickel, penny )
if 0 >= change:
print "Done!"