+ 2

Vending machine selection

I don't what to do

15th Nov 2024, 10:57 PM
Christian Francis
Christian Francis - avatar
1 Resposta
+ 8
Christian Francis Imagine you're programming a vending machine interface. The machine displays a list of products, and the user selects a product by entering its position in the list. To ensure the machine operates smoothly, it should handle cases where users input invalid positions without crashing. Task   The program below displays a list of products available in a vending machine and asks the user to select a product by entering its index. Complete the program so it either shows the selected product or prints wrong index if the entered index is out of range Sample Input: 8 Sample Output: wrong index Provided: products = ["Water", "Chocolate", "Chips", "Soda", "Sandwich"] choice_index = int(input()) Not provided ( task ) # Write a try-except block to display the selected product # or print "wrong index" if the input index is out of range
15th Nov 2024, 11:27 PM
BroFar
BroFar - avatar