练习

乘法表:

a = 1
while a <= 9 :
    b = 1
    while b <= a :
        print(str(b)+"*"+str(a)+"="+str(b*a),end="\t")
        b += 1
    print()
    a += 1

#print("\n".join("\t".join(["%s*%s=%s" %(x,y,x*y) for y in range(1, x+1)]) for x in range(1, 10)))



login:

# user = "abc"
# key = "123"
#
# for i in range(3):
#     user_name = input("user_name:")
#     password = input("password:")
#     if user_name ==user and password == key:
#         print("welcome %s login..."%user)
#         break
#     else:
#         print("invalid user_name or password")
# else:
#     print("密码输入次数过多")

user = "abc"
key = "123"
counter = 0
while counter < 3:
    user_name = input("user_name:")
    password = input("password:")
    if user_name ==user and password == key:
        print("welcome %s login..."%user)
        break
    else:
        print("invalid user_name or password")
    counter += 1
    if counter == 3:
        keep_going_choice = input("do you want to login?[y/n]")
        if keep_going_choice == "y":
            counter = 0
else:
    print("密码输入次数过多")



shopping:

a_list = [("iphone","8000"),("mac book","9000"),("coffee","32"),("Python book","80"),("bicyle","1500")]
salary = input("how much money you have:")
shopping_car = []
if salary.isdigit():
    salary = int(salary)
    while True:
        for i,v in enumerate(a_list,1):
            print(i,v)
        choice = input("选择商品编号【退出:q】")
        if choice.isdigit():
            choice = int(choice)
            if choice > 0 and choice <= len(a_list):
                p_item = a_list[choice-1]
                if int(p_item[1]) < salary:
                    salary -= int(p_item[1])
                    shopping_car.append(p_item)
                else:
                    print("余额不足,还剩%s"%salary)
                print(p_item)
        elif choice =="q":
            print("------------您已购买以下商品-------------")
            for i in shopping_car:
                print(i)
            print("你还剩%s元钱"%salary)
            break
        else:
            print("invalid input")



三級菜单:

menu = {
        '北京': {
            '朝阳': {
                '国贸':{
                    'CICC':{},
                    "HP":{},
                    'CCTV':{}
                },
                '望京':{
                    '默默':{},
                    "奔驰":{},
                    '360':{}
                },
                '三里屯':{
                    '优衣库':{},
                    "apple":{},
                }
            },
            '昌平': {
                '沙河':{
                    '老男孩':{},
                    '阿泰包子':{}
                },
                '天通苑':{
                    '链家': {},
                    '我爱我家': {}
                },
                "回龙观":{},
                },
            '海淀':{
                '五道口':{
                    '谷歌':{},
                    '网易':{},
                    '搜狐':{},
                    'shougou':{},
                },
                '中关村':{
                    'youku':{},
                    '汽车之家':{},
                }
            }

        },
        '上海':{},
        '山东':{}
    }
layer = menu
flayer = []
while True:
    for i in layer:
        print(i)
    choice = input('输入').strip()
    if len(choice) == 0:continue
    if choice in layer:
        flayer.append(layer)
        layer = layer[choice]
    elif choice == "b":
        if flayer:
            layer = flayer.pop()
    elif choice == "p":
        break
    else:
        print('无此项')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值