Python code not working- issues in 'while' - Q)a superstore has multiple items to sell and gives discount

p = 0
order = input('Enter no of items and category: ').split()
while order != ‘STOP’:
if order[1] == ‘A’:
if int(order[0]) < 30:
p = p + int(order[0])*15
elif int(order[0]) <99:
p = p + int(order[0])*12
else:
p = p + int(order[0])*10
order = input('Enter no of items and category: ').split()
else:
if int(order[0]) < 50:
p = p + int(order[0])*30
elif int(order[0]) < 99:
p = p + int(order[0])*25
else:
p = p + int(order[0])*20
order = input('Enter no of items and category: ').split()
else:
print(order)

ERROR - when I input stop, I get this error

IndexError Traceback (most recent call last)
Input In [36], in <cell line: 3>()
2 order = input('Enter no of items and category: ').split()
3 while order != ‘STOP’:
----> 4 if order[1] == ‘A’:
5 if int(order[0]) < 30:
6 p = p + int(order[0])*15

IndexError: list index out of range

You want the input ‘STOP’ to skip the while loop but [‘STOP’] is not equal to ‘STOP’.

Notice that the split method returns an array

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.