This question already has an answer here:
I have a while loop that isn't functioning correctly, but I can't work out why. When I run the code, only 'while' is supposed to carry out multiplication on 'overallPrice', but 'else' also does it, making the whole loop useless. The loop also repeats endlessly and I don't know how to stop it.
e.g. If 'numberOfRooms' = 2 and 'paperRemove' = Y or y, price correctly displays at £140. However, if 'numberOfRooms' = 2 and 'paperRemove' = N or n, the price still displays as £140, although it is meant to be £0. The latter result makes the whole loop useless to me.
Here is the section of code. Please note, everything is indented once extra because everything is within a function. Also, 'overallPrice' is set to 0 at the beginning of the code, but is not included here.
#Asking if wallpaper needs to be removed.
print ("\nDoes the customer's original wallpaper need to be removed?")
paperRemove = input ("\nPlease type Y for yes, or N for no: ")
#If paper does need removing, adds £70 to 'overallPrice' multiplied by 'numberOfRooms' if paper does not need
#removing, 'overallPrice' remains at 0?
while paperRemove == "Y" or "y":
overallPrice = overallPrice + 70 * numberOfRooms
print ("The overall Price (Exc VAT.) is currently £",overallPrice)
else:
overallPrice = overallPrice + 0
print ("The overall Price (Exc VAT.) is currently £",overallPrice)
#Next code beneath this.
Aucun commentaire:
Enregistrer un commentaire