• Python学习3


    猜数游戏

    import random
    while True:
    first=random.randrange(100)
    while True:
    second=int(input('请猜'))
    if first>second:
    print('小了')
    elif first==second:
    print('对了')
    break
    else:
    print('大了')



    购物车

    flag = 'ok'
    lists = []
    goods_lists = [['水果',[['鸭梨',18],['桃子',30],['苹果',21],['榴莲',5],['香蕉',3]]],['蔬菜',[['胡萝卜',11],['香菜',21],['圆白菜',3],['土豆',2],['地瓜',4]]]]
    while True:
    if flag=='no':
    total_price = 0
    print('商品名称 单价 购买数量 购买总价')
    for a, b, c, d in lists:
    print(' ' + a, ' ' * 3 + str(b), ' ' * 3 + str(c), ' ' * 3 + str(d))
    total_price += d
    print('总价格为' + str(total_price))
    break
    n = 1
    print('欢迎光临 XXX超市')
    print('################################')
    for a,b in goods_lists:
    print(' '+str(n)+' '+a)
    n = n+1
    print('################################')
    num1 = int(input('请选择分类序号:')) - 1
    while True:
    m = 1
    print('欢迎光临 XXX超市')
    print('################################')
    for goods in goods_lists[num1][1]:
    print(' '+str(m)+' '+goods[0]+' '+str(goods[1])+'元')
    m = m + 1
    print('################################')
    num2 = int(input('请选择商品序号:'))-1
    if num2==-1:
    break
    if num2==-2:
    flag = 'no'
    break
    n_lists = []
    num3 = int(input('请选择购买数量(输入0返回上级菜单,输入-1结算退出)'))
    n_lists.append(goods_lists[num1][1][num2][0])
    n_lists.append(goods_lists[num1][1][num2][1])
    n_lists.append(num3)
    n_lists.append(goods_lists[num1][1][num2][1]*num3)
    lists.append(n_lists)


    我的


    flag = 'ok'
    lists = []
    goods_lists = [['水果', [['苹果', 5], ['葡萄', 10], ['草莓', 15], ['芒果', 8], ['橘子', 6]]]
    , ['蔬菜', [['胡萝卜', 2], ['土豆', 1], ['芹菜', 3], ['菠菜', 4], ['大葱', 1]]]]
    while True:
    if flag == 'no':
    total_price = 0
    print('商品名称 单价 数量 总价')
    for a, b, c, d in lists:
    print(' ' + a, ' ' * 3 + str(b), ' ' * 3 + str(c), ' ' * 3 + str(d))
    total_price += d
    print('总价为' + str(total_price))
    break

    n = 1
    print('欢迎光临55超市')
    print('########################')
    for a, b in goods_lists:
    print(' '+str(n)+' '+a)
    n = n + 1
    print('########################')

    num1 = int(str(input('请选择分类序号:'))) - 1
    while True:
    m = 1
    print('欢迎光临55超市')
    print('########################')
    for goods in goods_lists[num1][1]:
    print(' '+str(m)+' '+goods[0]+' '+str(goods[1])+'元')
    m = m + 1
    print('########################')
    num2 = int(str(input('请选择商品序号:'))) - 1
    if num2 == -1:
    break
    if num2 == -2:
    flag = 'no'
    break
    n_lists = []
    num3 = int(str(input('请选择购买数量(输入0返回上级菜单,输入-1结算退出)')))
    n_lists.append(goods_lists[num1][1][num2][0])
    n_lists.append(goods_lists[num1][1][num2][1])
    n_lists.append(num3)
    n_lists.append(goods_lists[num1][1][num2][1] * num3)
    lists.append(n_lists)


  • 相关阅读:
    KDD 2018 | 最佳论文:首个面向Facebook、arXiv网络图类的对抗攻击研究
    Distill详述「可微图像参数化」:神经网络可视化和风格迁移利器!
    T1330 最少步数(#Ⅱ- 8)(广度优先搜索)
    细胞个数题解(广度优先搜索)
    DRL前沿之:Benchmarking Deep Reinforcement Learning for Continuous Control
    DRL 教程 | 如何保持运动小车上的旗杆屹立不倒?TensorFlow利用A3C算法训练智能体玩CartPole游戏
    强化学习是如何解决问题的?
    深度强化学习泡沫及路在何方?
    ECCV 2018 | UBC&腾讯AI Lab提出首个模块化GAN架构,搞定任意图像PS组合
    纵览神经架构搜索方法
  • 原文地址:https://www.cnblogs.com/tangmf/p/14011115.html
Copyright © 2020-2023  润新知