我自己 diy 了一个饮品店系统可出现错误,希望能来帮帮我

goods=['1.卡布奇诺\n','2.拿铁\n','3.猫屎咖啡\n','4.可乐\n','5.雪碧\n','6.芬达\n','7北冰洋\n','8.鲜榨果汁',]
print('欢迎来到米其林自主饮品店qwq')
print('本店周六日打7折呦')
print('本店的饮品有',goods)
print('请问您想要什么饮料呢?(请输入产品序号)')
needs=int(input())
while true:
    if needs==1:
        payneeds=14# <==报错说这应是缩进块
    elif needs==2:
        payneeds=15
    elif  needs==3:
        payneeds=30
    elif needs==4:
        payneeds=4
    elif needs==5:
        payneeds=3
    elif needs==6:
        payneeds=4
    elif needs==7:
        payneeds=5
    else needs==7:
        payneeds=10
payneeds=int(needs*0.7)
print('原价',needs,'元')
讨论数量: 2
goods=['1.卡布奇诺','2.拿铁','3.猫屎咖啡','4.可乐','5.雪碧','6.芬达','7北冰洋','8.鲜榨果汁',]
print('欢迎来到米其林自主饮品店qwq')
print('本店周六日打7折呦')
print('本店的饮品有',goods)
print('请问您想要什么饮料呢?(请输入产品序号)')
needs=input()
while true:
    if needs==1:
    payneeds=14#错误1,后面还有很多这样的错误,就用^来表示
    elif needs==2:
    payneeds=15 ^
    elif needs==3:
    payneeds=30 ^
    elif needs==4:
    payneeds=4 ^
    elif needs==5:
    payneeds=3 ^
    elif needs==6:
    payneeds=4 ^
    elif needs==7:
    payneeds=5 ^
    else needs==7:
    payneeds=10 ^
payneeds=int(needs*0.7)错误二
print('原价',needs,'元')

错误1(^):缩进没加
错误2:input会把输入的内容变成字符串,如果你这样写的话,逻辑就会变成:“把needs0.7的值变为数字,而不是把needs变为数字之后乘0.7”你这个应该改int(needs)0.7
正确代码:

goods=['1.卡布奇诺','2.拿铁','3.猫屎咖啡','4.可乐','5.雪碧','6.芬达','7北冰洋','8.鲜榨果汁',]
print('欢迎来到米其林自主饮品店qwq')
print('本店周六日打7折呦')
print('本店的饮品有',goods)
print('请问您想要什么饮料呢?(请输入产品序号)')
needs=input()
while true:
    if needs==1:
        payneeds=14# <==报错说这应是缩进块
    elif needs==2:
        payneeds=15
    elif  needs==3:
        payneeds=30
    elif needs==4:
        payneeds=4
    elif needs==5:
        payneeds=3
    elif needs==6:
        payneeds=4
    elif needs==7:
        payneeds=5
    else needs==7:
        payneeds=10
payneeds_now=int(needs)*0.7
print('原价',payneeds,'元')
print('现价',payneeds_now,'元')
3年前 评论
Jason990420

供参考

from datetime import datetime

def length(text):
    l = 0
    for c in text:
        l += 1 if c in ASCII else 2
    return l
ASCII = [chr(i) for i in range(256)]

goods = {
            '1':['卡布奇诺', 14],
            '2':['拿铁',     15],
            '3':['猫屎咖啡', 30],
            '4':['可乐',      4],
            '5':['雪碧',      4],
            '6':['芬达',      4],
            '7':['北冰洋',    5],
            '8':['鲜榨果汁', 10],
         }
listing = '\n'.join([key.center(9) +
                     goods[key][0] + ' '*(20-length(goods[key][0])) +
                     '{:>6d}'.format(goods[key][1])
                        for key in sorted(goods.keys())])

welcome = f"""
欢迎光臨

~ 米其林自主饮品店 ~

  本店周六日打7折呦
  本店的饮品有

产品序号 产品名称             产品单价
-------- -------------------- --------
{listing}

请问您想要什么饮料呢? (请输入产品序号)"""

print(welcome)

while True:
    discount = 0.7 if datetime.now().weekday() in [5, 6] else 1
    try:
        needs = input().strip()
    except:
        continue
    if needs in goods:
        list_price = goods[needs][1]
        pay_price  = round(list_price * discount, 1)
        if discount < 1:
            print(f'>>> 原价 {list_price} 元, 目前打 {discount*10} 折, 只收 {pay_price} 元.')
        else:
            print(f'>>> 原价 {list_price} 元, 今天没有打折, 收 {pay_price} 元.')

    elif needs == '0':
        break

    else:
        print('>>> 产品序号不存在, 请重新输入')

print('~ 欢迎再度光临 ~')
3年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!