Hi there, newbie to python and in need of help for an assignment.

I have to write a Python program that prompts the user to input the before-tax price of an item and
the payment from the customer. It should then perform two tasks. First, compute and display the
after-tax price, assuming a tax rate of 5%. Second, compute the change owed to the customer, and break that down
into dollars, quarters, dimes and pennies, with the total number of coins in the breakdown minimized. Display such breakdown information.Note, if the after-tax price includes a certain fraction of a penny, ignore that fraction.

Thanks for the help!

## Xantipius 15

``````x = input('Enter the before-tax price (in cents):')
y = input('Enter your painment (in cents):')
z = y - int(1.05 * x)
print '\$:', z / 100
z = z % 100
print 'quarters:', z / 25
z = z % 25
print 'dimes:', z / 10
z = z % 10
print 'pennies:', z
``````

PS
PPS
Maybe the penny = 5 cents? I assumed it is = 1 cent.

commented: might accidentally a nickel? +3

## Lardmeister 461

hotblink (Christopher Dela Paz) you should give at least an attempt to code this yourself. Most of us frown on doing homework for you.

## woooee 814

FWIW, you can also use divmod instead of two statements (divide and mod), but I doubt that this code would be accepted from a beginning student, and only prints the plural form of the words.

``````x = input('Enter the before-tax price (in cents): ')
y = input('Enter your painment (in cents): ')
z = y - int(1.05 * x)
print 'Your change is: ', z
for divisor, lit in [(100, "Dollars"), (25, "Quarters"),
(10, "Dimes"), (5, "Nickels"), (1, "Pennies")]:
whole, z = divmod(z, divisor)
print "%9s = %d" % (lit, whole)
``````

hotblink (Christopher Dela Paz) you should give at least an attempt to code this yourself. Most of us frown on doing homework for you.

+1

## Xantipius 15

I think the nickels are missed here on purpose. E.g.,
80 = 3 * 25 + 5 * 1 => 8 coins
80 = 2 * 25 + 3 * 10 => 5 coins (required minimum)

## Xantipius 15

``````x = input('Enter the before-tax price (in cents): ')
y = input('Enter your painment (in cents): ')
z = y - int(1.05 * x)

ans = [0, 0, 0, z]
a = [z / 100, 0, 0, 0]
i = a
for j in range(0, (z - i * 100) / 25 + 1):
a = j
for k in range(0, (z - i * 100 - j * 25) / 10 + 1):
a = k
a = z - i * 100 - j * 25 - k * 10
if sum(a) < sum(ans):
ans = a[:]

print 'Dollars =', a
print 'Quarters =', a
print 'Dimes =', a
print 'Pennies =', a

Enter the before-tax price (in cents): 3456
Enter your painment (in cents): 56789
Dollars = 531
Quarters = 2
Dimes = 1
Pennies = 1
``````

## vegaseat 1,735

Cute, a payment can be a painment.

## Xantipius 15

Cute, a payment can be a painment.

heh You are right!
Plus, I slipped typos at the very end of my code (should be "ans[]", not "a[]").

``````x = input('Enter the before-tax price (in cents): ')
y = input('Enter your painment (in cents): ')
z = y - int(1.05 * x)

ans = [0, 0, 0, z]
a = [z / 100, 0, 0, 0]
i = a
for j in range(0, (z - i * 100) / 25 + 1):
a = j
a = (z - i * 100 - j * 25) / 10
k = a
a = z - i * 100 - j * 25 - k * 10
if sum(a) < sum(ans):
ans = a[:]

print 'Dollars =', ans
print 'Quarters =', ans
print 'Dimes =', ans
print 'Pennies =', ans

###########################################

Enter the before-tax price (in cents): 3438
Enter your painment (in cents): 56789