需求一:
用户名和密码存放于文件中,格式为:rocco|rocco123
启动程序后,先登录,登录成功则让用户输入工资,然后打印商品列表,失败则重新登录,超过三次则退出程序
允许用户根据商品编号购买商品
用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
可随时退出,退出时,打印已购买商品和余额
commodity = [ ['1', '可口可乐', 3.5], ['2', '奶茶', 15], ['3', '鸡排', 20], ['4', '薯片', 5], ['5', '冰棒', 5], ['6', 'time', 9999999999] ] count = 0 tag = True select_name = [] u_salary = [] while tag: if count == 3: print("失败次数过多,退出") break inp_user = input("输入用户名:").strip() inp_pwd = input("输入密码:").strip() with open('Text', 'r', encoding='utf-8') as usepwd: for i in usepwd: user = i.strip().split('|') username = user[0] pwd = user[1] if inp_user == username and inp_pwd == pwd: print(f"{username} :用户登陆成功") # tag = False while tag: salary = input("请输入你的工资: ").strip() u_salary.append(salary) if salary.replace(".", "", 1).isdigit(): print("sum ok") print("商品列表".center(50, "=")) print("\t\t\t商品ID\t商品名\t\t单价") for i in commodity: print("\t\t\t{id}\t\t{mz}\t\t{jq}".format(id=i[0], mz=i[1], jq=i[2])) while tag: mai = input("输入商品编号购买|输入b退出:").strip() if mai == 'b': tag = False break for v in commodity: print(v) if mai in v: print(f"是否购买: {v[1]}") if int(v[2]) <= int(salary): select_name.append(v) print(f"{salary}你购买前的余额") salary = int(salary) - int(v[2]) print(f"{salary}你购买后的余额") else: print("余额不足,请充值!!") break else: print("登陆失败,再次尝试!") count += 1 print(f"最终商品 {select_name} \n最终余额 {salary}")
需求二:
打印二级三级四级菜单
area = { '北京': { '海淀': { '五道口': { 'soho': {}, '网易': {}, 'google': {} }, '中关村': { '爱奇艺': {}, '汽车之家': {}, 'youku': {}, }, '上地': { '百度': {}, }, }, '昌平': { '沙河': { '老男孩': {}, '北航': {}, }, '天通苑': {}, '回龙观': {}, }, '朝阳': {}, '东城': {}, }, '上海': { '闵行': { "人民广场": { '炸鸡店': {} } }, '闸北': { '火车战': { '携程': {} } }, '浦东': {}, }, '山东': {}, } case = True while case: read_case = area for city in read_case: print(city) inp_city = input("输入查询的城市: ").strip() if inp_city == "back": break if inp_city == "quit": case = False continue if inp_city not in read_case: print("城市不存在,查证后重新输入!!") continue while case: read_case_2 = read_case[inp_city] for Area in read_case_2: print(Area) inp_Area = input("输入城市所在区:").strip() if inp_Area == "back": break if inp_Area == "quit": case = False continue if inp_Area not in read_case_2: print("区不存在!!!") continue while case: read_case_3 = read_case_2[inp_Area] for street in read_case_3: print(street) inp_street = input("输入所在街道:").strip() if inp_street == "back": break if inp_street == "quit": case = False continue if inp_street not in read_case_3: # print(f"没有这个街道") continue while case: read_case_4 = read_case_3[inp_street] for store in read_case_4: print(store) inp_store = input("输入商铺|公司").strip() if inp_store == "back": break if inp_store == "quit": case = False continue if inp_store not in read_case_4: continue
需求三:
打印99乘法表
for i in range(1, 10): for v in range(1, i + 1): # print(i, "*", v, "=", i * v, end="\t") print(f"{i} * {v} = {i * v}", end="\t") print()
最新评论
# 这只是一个创建远程登录并授权的语句、仅作为记录 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Fit2cloud!' WITH GRANT OPTION;
当MGR集群初始化结束后,需要开启MGR集群自启动(需要有一台节点是自动开启引导) loose-group_replication_start_on_boot = ON #设置节点是否在启动时自动启动 MGR 集群 loose-group_replication_bootstrap_group = ON #设置节点是否作为初始引导节点启动集群
密码:blog.sirliu.com
本内容密码:blog.sirliu.com 最新整理的文章在这里喔:https://blog.sirliu.com/2018/11/shell_lian_xi_ti.html