- 4

Python Start

How to solve?The program must ask for a category and an amount until it receives the word "cancel" instead of a category. 1) When the word "cancel" is entered instead of a category, the program should display "Purchase closed" and turn off. 2) After receiving the cost of the goods, the program must, depending on the category, apply a certain discount and show the amount to be paid on the screen. Then you must apply for a category again. 3) If there are no discounts for the category, the program must show the amount to pay without applying discounts. Discounts available: Dairy products - 10% discount. Baked Goods - 30% discount. Write such a program. A possible result of the program is shown in the image. I solved it as follows: while True: a= input('Introduce la categoría:') if (a=='cancelar'): print('Compra cerrada') break else: b= float(input('Introduce el precio del producto:')) if (a=='productos lácteos'): c= 10 elif (a=='productos horneados'): c= 30 else: c= 0 print('Descuento de', str(c)+'%. Por pagar:', b-(b*c/100)) Is there another way to shorten the code?

29th Sep 2021, 7:51 PM
kerly cervantes
kerly cervantes - avatar
1 Odpowiedź
+ 2
This is not a free do-my-homework service.
29th Sep 2021, 7:52 PM
Simon Sauter
Simon Sauter - avatar