zoukankan      html  css  js  c++  java
  • 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)


  • 相关阅读:
    PTA(Basic Level)1012.数字分类
    PTA(Basic Level)1011.A+B和C
    PTA(Basic Level)1008.数组元素循环右移问题
    PTA(Basic Level)1009.说反话
    PTA(Basic Level)1010.一元多项式求导
    Leetcode 38.报数 By Python
    Leetcode 35.搜索插入位置 By Python
    查看Linux的所有线程
    Linux内核模块编程——Hello World模块
    JSP内置对象总结
  • 原文地址:https://www.cnblogs.com/tangmf/p/14011115.html
Copyright © 2011-2022 走看看