On 05/04/2015 07:08 PM, Jag Sherrington wrote:
Hi, Alan>



Please don't top-post. Enter your new message *after* whatever portion of the previous message you're quoting. I'm rearranging the portion of your message to conform to that standard.



      On Monday, 4 May 2015, 17:35, Alan Gauld <alan.ga...@btinternet.com> 
wrote:


# Process one or more items.
while another == 'y' or another == 'y':

That's the same test twice. Is that what you meant?

       #Get the item 's wholesale cost'
       wholesale = float(input("Enter the item's wholesale cost: "))

       # Validate the wholesale cost.
       while wholesale < 0:
           print('ERROR: the cost cannot be negative.')
           wholesale = float(input('Enter the correct wholesale cost: '))

BUG on following line:
           #Calculate the retail price.
           retail = wholesale * mark_up

           #Display the retail price.
           print('Retail price: $', format(retail, ',.2f'), sep='')

           #Do this again.
           another = input('Do you have another item? ' + \
                           '(Enter y for yes): ')

HERE ARE THE RESULTS:

Enter the item's wholesale cost: 0.50
Enter the item's wholesale cost:    (THIS SEEMS TO BE A PROBLEM)

No problem, its exactly what your program tells it to do.
If the cost is >0 there is nothing else to do so it goes
round the loop a second time.

What did you expect it to do?

> Enter the item's wholesale cost: 0.50 (AFTER THIS LINE PRINTS I HIT
> ENTER AND WOULD EXPECT THE NEXT LINE TO GIVE ME THE RESULT>
> Enter the item's wholesale cost:    "Retail price: $1.25"
> INSTEAD WHEN I HIT ENTER I GET "Enter the item's
>  wholesale cost: " AGAIN AND AGAIN

(See Peter's comment as well as Alan's second one.)

All the rest of your logic is inside the while loop that's only run when the wholesale < 0 branch is taken. So you don't see any output from it, as it never runs unless you enter a negative value followed by a positive one.

You have to fix the indentation of the lines starting "#Calculate the retail price"



--
DaveA
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to