|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- print("Welcom to OUR STORE.\nPlease enter your choice below")#导入语
- global choice
- choice = input("please enter your choice:") #输入选择
- #预存的列表
- LU = []#锁定的用户
- in_user = []
- UP_user = []#现有用户
- UP_pw = []#现有用户的密码
- count = 0 #输入密码次数
- Score_list = []#储存用户积分
- shop = [['1','iphone8',5888],['2','kndle',988],['3','ps4 pro',2800],['4','psv',1200],['5','psvtv',450],['6','ps4 controler',230],['7','mp3',100]]
- #商店货物
- def first_page():
- print("1:log in\n2:register\n3:check score\n4:shopping\n5:log out")#选项
- def log_in():
- if choice == 1:
- global user
- user = input("your name:")
- global password
- password = input("please enter your password:")
- while user in UP_user :
- if password == UP_pw[UP_user.index()]:
- print("登陆成功")
- else:
- while count <= 3:
- pw = input("请再次输入您的密码,三次输入失败后用户将被锁定:")
- if pw == UP_pw[UP_user.index()]:
- in_user.append(user)
- print("登陆成功")
- else:
- count += 1
- print("密码错误")
- if count == 3:
- LU.append(user)
- print("您输入密码次数过多,用户已被锁定")
- first_page()
- else:
- if user in LU:
- print("该用户已被锁定")
- else:
- print(user + "用户未注册")
- return
- def register():
- global new_user
- new_user = input("请输入您想拥有的用户名:")
- b = 1
- while b == 1:
- if new_user in UP_user:
- print("该用户已被注册")
- new_user = input("请再次输入您的用户名:")
- else:
- print(new_user + "用户名可用")
- UP_user.append(new_user)
- a = 1
- while a == 1:
- global password
- password = input("请输入您的密码:")
- print("密码安全系数的标准:\n低级密码要求:\n1. 密码由单纯的数字或字母组成\n2. 密码长度小于等于 8 位\n\n中级密码要求:\n1. 密码必须由数字、字母或特殊字符(仅限: )任意两种组合\n2. 密码长度不能低于 8 位\n高级密码要求\n1. 密码必须由数字、字母及特殊字符(仅限: )三种组合\n2. 密码只能由字母开头\n3. 密码长度不能低于 16 位")
- symbols = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''
- chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
- nums = '0123456789'
- # 判断长度
- length = len(password)
- while (passwordd.isspace() or length == 0) :
- password = input(" 您输入的密码为空(或空格),请重新输入: ")
- if length <= 8:
- flag_len = 1
- elif 8 < length < 16:
- flag_len = 2
- else:
- flag_len = 3
- flag_con = 0
- # 判断是否包含特殊字符
- for each in password:
- if each in symbols:
- flag_con += 1
- break
- # 判断是否包含字母
- for each in password:
- if each in chars:
- flag_con += 1
- break
- # 判断是否包含数字
- for each in password:
- if each in nums:
- flag_con += 1
- break
- # 打印结果
- while 1 :
- print(" 您的密码安全级别评定为: ", end='')
- if flag_len == 1 or flag_con == 1 :
- print("低")
- value = 0
- elif flag_len == 2 or flag_con == 2 :
- print(" 中")
- value = 0
- else :
- print(" 高")
- value = 1
- break
- if value == 1:
- UP_pw.append(password)
- Score_list.append(0)
- print("注册成功")
- break
- else:
- print(" 请按以下方式提升您的密码安全级别: \n\ \t1. 密码必须由数字、字母及特殊字符三种组合 \n\ \t2. 密码只能由字母开头 \n\ \t3. 密码长度不能低于 16 位'")
- continue
- return
- def check_score():
- d = 1
- if choice == 2:
- print("your score :" + Score_list[member.index('user')])
- while d == 1:
- if scoreScore_list[member.index('user')] >= 2000:
- print("—————————您是本店VVIP——————————————")
- print("您可享有六折优惠")
- return
- elif Score_list[member.index('user')] < 2000:
- print("—————————您是本店VIP——————————————")
- print("您可享有八折优惠")
- return
- while Score_list[member.index('user')] ==0:
- print("—————————您是本店普通用户——————————————")
- print("您可享有九折优惠")
- return
- def shopping():
- i = 1#为了通过修改i 退出多重循环
- allchoice = []
- discount = 1
- w = 1
- while Score_list[member.index('user')] !=0:
- if Score_list[member.index('user')] >= 2000:
- discount = 0.6
- elif Score_list[member.index('user')] < 2000:
- discount = 0.8
- while Score_list[member.index('user')] == 0:
- discount = 0.9
- while(i):
- for num in range(len(shop)): # 打印商品列表
- print(str(shop[num][0]).ljust(5), shop[num][1].ljust(20), str(shop[num][2]).ljust(10), )
- choice = input("请输入要加入购物车的商品编号:")
- choice = [int(it) for it in choice.split(' ')]
- allchoice += choice #choice是单次选择的商品列表,allchoice是所有选择的商品列表
- while(1):
- global total
- total = 0
- choiceSet = set(allchoice)#转换成集合,便于不重复计数
- for it in choiceSet:
- print(shop[it-1][0],shop[it-1][1],shop[it-1][2],'*',allchoice.count(it))
- total += shop[it-1][2]*allchoice.count(it)*discount
- print("总计:",total,"已优惠:",shop[it-1][2]*allchoice.count(it)*(1-discount))
- print("---------------------------------\n"
- "1:继续选购 2:整理购物车 3:结算\n")
- option = int(input( "请选择:"))
- if option == 1:
- break
- elif option == 2:
- item_num = int(input("请输入要删除的商品"))
- allchoice.remove(item_num)#每次只会删除一个元素
- continue
- else:
- print("您需要支付的金额为:" , total)
- score += total
- first_page()
- run = 1
- while run == 1:
- if choice == 1:
- log_in()
- first_page()
- elif choice == 2:
- register()
- first_page()
- elif choice == 3:
- check_score()
- first_page()
- elif choice == 4:
- shopping()
- first_page()
- if choice == 5:
- run -= 1
- if run == 0:
- in_user.remove(user)
- print("See u next time.")
-
-
-
-
-
-
复制代码 |
|