输出商品列表,用户输入序号,显示用户选中的商品
商品 li = ['手机','电脑','鼠标','游艇']
求:1:页面显示序号,商品名称,如
1 手机
2 电脑
....:
2, 用户输入选择的商品序号,然后打印商品名称
3,如果输入的商品序号有误,则显示输入有,并且重新输入
用户输入Q 或者q 退出运行程序
程序代码
li = ['手机','电脑','鼠标','游艇']
i = 0
sum = 0
while 1:
if i == 4:
n = input('请输入你选择的商品序列号:')
if n == '1':
print('手机')
elif n == '2':
print('电脑')
elif n == '3':
print('鼠标')
elif n == '4':
print('游艇')
elif n.strip().upper() == 'Q':
print('谢谢使用,欢迎下次在来')
break
else:
print('输入有误')
if i <len(li):
name = li[i]
print(str(sum) + ' ' + name)
i +=1
sum +=1