-1

This program will ask a user for a unit price and quantity. It will then multiply the unit price by the quantity. If quantity is greater than 10, put in a 5% discount. If quantity is greater than 100, put in a 10% discount.

def bmth(unit, quan):
    def computeN(unit, quan):
        z = unit * quan
        print(z)

    if 10 <= quan < 99:
        ordercost = unit * quan
        discfive = ordercost * .05
        v = ordercost - discfive
        print('Your original price was ', ordercost)
        print('You Saved', discfive, 'off')
        print('Your new price is now ', v)
    elif quan >= 100:
        ordercost2 = unit * quan
        discten = ordercost2 * .10
        n = ordercost2 - discten
        print('Your original price was ', ordercost2)
        print('You save ', discten, 'off')
        print('Your new price is now ', n)
    else:
        computeN(unit, quan)

while True:
    unit = float(input('Enter the Unit price: '))
    quan = int(input('Enter your items: '))
    onelasttime = input('Do you wish to continue? Y or N: ')
    Y = bmth(unit, quan)
    if onelasttime:
        input(Y)
    elif onelasttime:
        input(N)
    break
aaron
  • 39,695
  • 6
  • 46
  • 102
Ulquiorra
  • 1
  • 1

1 Answers1

0

Fixed your while loop:

while True:
    unit = float(input('Enter the Unit price: '))
    quan = int(input('Enter your items: '))
    not_continue = input('Do you wish to continue? Y or N: ') is 'N'
    bmth(unit, quan)
    if not_continue:
        break

Observe that:

  1. onelasttime is a string, so 'N' is truthy and evaluates to True.
  2. bmth doesn't return, so Y = bmth(unit, quan) is always None.
  3. If your break is not in an if, then while will break on first loop.
aaron
  • 39,695
  • 6
  • 46
  • 102