python基础学习day4/练习题

#练习1:列表倒数
a=[123,4567,12,3456]
i=0
while i

    b=0
    while a[i]>0:
        b=b*10+a[i]%10
        a[i]//=10
    a[i]=b
    i+=1
print(a)

#练习2:售货机
lst = ["手机","电脑","鼠标","平板"]
ret = lst.index("手机")
print(ret)

for product in lst:
    print("商品%s的序号为%d"%(product,lst.index(product)+1))

for index,product in enumerate(lst,start=1):
    msg = "商品序号{},商品名称{}".format(index,product)
    print(msg)

while True:
    value = input("请输入要购买的商品的序号,输入Q/q结束")

    if value.upper() == "Q":
        print("程序结束")
        break
    elif value.isdigit():
        num = int(value)
        if num>0 and num             print(lst[num-1])
        else:
            print("输入错误,请重新输入")

    else:
        print("输入不正确,请重新输入")

你可能感兴趣的:(python基础学习day4/练习题)