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!

Just for to start with smth...

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:'
print '$:', z / 100
z = z % 100
print 'quarters:', z / 25
z = z % 25
print 'dimes:', z / 10
z = z % 10
print 'pennies:', z

PS
It does not minimize answers.
PPS
Maybe the penny = 5 cents? I assumed it is = 1 cent.

commented: might accidentally a nickel? +3

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

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

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)

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[0]
for j in range(0, (z - i * 100) / 25 + 1):
    a[1] = j
    for k in range(0, (z - i * 100 - j * 25) / 10 + 1):
        a[2] = k
        a[3] = z - i * 100 - j * 25 - k * 10
        if sum(a) < sum(ans):
            ans = a[:]

print 'Your change is:', z
print 'Dollars =', a[0]
print 'Quarters =', a[1]
print 'Dimes =', a[2]
print 'Pennies =', a[3]


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

Cute, a payment can be a painment.

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[0]
for j in range(0, (z - i * 100) / 25 + 1):
    a[1] = j
    a[2] = (z - i * 100 - j * 25) / 10
    k = a[2]
    a[3] = z - i * 100 - j * 25 - k * 10
    if sum(a) < sum(ans):
        ans = a[:]

print 'Your change is:', z
print 'Dollars =', ans[0]
print 'Quarters =', ans[1]
print 'Dimes =', ans[2]
print 'Pennies =', ans[3]

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

Enter the before-tax price (in cents): 3438
Enter your painment (in cents): 56789
Your change is: 53180
Dollars = 531
Quarters = 2
Dimes = 3
Pennies = 0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.