鱼C论坛

 找回密码
 立即注册
查看: 2016|回复: 2

请问为什么输入选择后不执行对应的函数

[复制链接]
发表于 2019-12-8 13:14:20 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. print("Welcom to OUR STORE.\nPlease enter your choice below")#导入语
  2. global choice
  3. choice = input("please enter your choice:") #输入选择
  4. #预存的列表
  5. LU = []#锁定的用户
  6. in_user = []
  7. UP_user = []#现有用户
  8. UP_pw = []#现有用户的密码
  9. count = 0 #输入密码次数
  10. Score_list = []#储存用户积分
  11. shop = [['1','iphone8',5888],['2','kndle',988],['3','ps4 pro',2800],['4','psv',1200],['5','psvtv',450],['6','ps4 controler',230],['7','mp3',100]]
  12. #商店货物
  13. def first_page():
  14.     print("1:log in\n2:register\n3:check score\n4:shopping\n5:log out")#选项
  15. def log_in():
  16.     if choice == 1:
  17.         global user
  18.         user = input("your name:")
  19.         global password
  20.         password = input("please enter your password:")
  21.         while user in UP_user :
  22.             if password == UP_pw[UP_user.index()]:
  23.                 print("登陆成功")
  24.             else:
  25.                 while count <= 3:
  26.                     pw = input("请再次输入您的密码,三次输入失败后用户将被锁定:")
  27.                     if pw == UP_pw[UP_user.index()]:
  28.                         in_user.append(user)
  29.                         print("登陆成功")
  30.                     else:
  31.                         count += 1
  32.                         print("密码错误")
  33.                 if count == 3:
  34.                     LU.append(user)
  35.                     print("您输入密码次数过多,用户已被锁定")
  36.         first_page()
  37.     else:
  38.         if user in LU:
  39.             print("该用户已被锁定")
  40.         else:
  41.             print(user + "用户未注册")
  42.     return
  43. def register():
  44.     global new_user
  45.     new_user = input("请输入您想拥有的用户名:")
  46.     b = 1
  47.     while b == 1:
  48.         if new_user in UP_user:
  49.             print("该用户已被注册")
  50.             new_user = input("请再次输入您的用户名:")
  51.         else:
  52.             print(new_user + "用户名可用")
  53.             UP_user.append(new_user)
  54.             a = 1
  55.             while a == 1:
  56.                 global password
  57.                 password = input("请输入您的密码:")
  58.                 print("密码安全系数的标准:\n低级密码要求:\n1. 密码由单纯的数字或字母组成\n2. 密码长度小于等于 8 位\n\n中级密码要求:\n1. 密码必须由数字、字母或特殊字符(仅限: )任意两种组合\n2. 密码长度不能低于 8 位\n高级密码要求\n1. 密码必须由数字、字母及特殊字符(仅限: )三种组合\n2. 密码只能由字母开头\n3. 密码长度不能低于 16 位")
  59.                 symbols = r'''`!@#$%^&*()_+-=/*{}[]\|'";:/?,.<>'''
  60.                 chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  61.                 nums = '0123456789'
  62.         # 判断长度
  63.                 length = len(password)
  64.                 while (passwordd.isspace() or length == 0) :
  65.                     password = input(" 您输入的密码为空(或空格),请重新输入: ")
  66.                 if length <= 8:
  67.                     flag_len = 1
  68.                 elif 8 < length < 16:
  69.                     flag_len = 2
  70.                 else:
  71.                     flag_len = 3
  72.                     flag_con = 0
  73. # 判断是否包含特殊字符
  74.                 for each in password:
  75.                     if each in symbols:
  76.                        flag_con += 1
  77.                     break

  78. # 判断是否包含字母
  79.                 for each in password:
  80.                     if each in chars:
  81.                        flag_con += 1
  82.                        break

  83. # 判断是否包含数字
  84.                 for each in password:
  85.                     if each in nums:
  86.                        flag_con += 1
  87.                        break  
  88. # 打印结果
  89.                 while 1 :
  90.                      print(" 您的密码安全级别评定为: ", end='')
  91.                 if flag_len == 1 or flag_con == 1 :
  92.                     print("低")
  93.                     value = 0
  94.                 elif flag_len == 2 or flag_con == 2 :
  95.                     print(" 中")
  96.                     value = 0
  97.                 else :
  98.                     print(" 高")
  99.                     value = 1
  100.                     break
  101.                 if value == 1:
  102.                     UP_pw.append(password)
  103.                     Score_list.append(0)
  104.                     print("注册成功")
  105.                     break
  106.                 else:
  107.                       print(" 请按以下方式提升您的密码安全级别: \n\ \t1. 密码必须由数字、字母及特殊字符三种组合 \n\ \t2. 密码只能由字母开头 \n\ \t3. 密码长度不能低于 16 位'")
  108.                       continue
  109.                 return
  110. def check_score():
  111.     d = 1
  112.     if choice == 2:
  113.         print("your score :" + Score_list[member.index('user')])
  114.     while d == 1:
  115.         if scoreScore_list[member.index('user')] >= 2000:
  116.             print("—————————您是本店VVIP——————————————")
  117.             print("您可享有六折优惠")
  118.             return
  119.         elif Score_list[member.index('user')] < 2000:
  120.             print("—————————您是本店VIP——————————————")
  121.             print("您可享有八折优惠")
  122.             return     
  123.         while Score_list[member.index('user')] ==0:
  124.             print("—————————您是本店普通用户——————————————")
  125.             print("您可享有九折优惠")
  126.     return
  127. def shopping():
  128.     i = 1#为了通过修改i 退出多重循环
  129.     allchoice = []
  130.     discount = 1
  131.     w = 1
  132.     while Score_list[member.index('user')] !=0:
  133.         if Score_list[member.index('user')] >= 2000:
  134.             discount = 0.6
  135.         elif Score_list[member.index('user')] < 2000:
  136.             discount = 0.8
  137.     while Score_list[member.index('user')] == 0:
  138.         discount = 0.9
  139.     while(i):
  140.         for num in range(len(shop)):  # 打印商品列表
  141.             print(str(shop[num][0]).ljust(5), shop[num][1].ljust(20), str(shop[num][2]).ljust(10), )
  142.         choice = input("请输入要加入购物车的商品编号:")
  143.         choice = [int(it) for it in choice.split(' ')]
  144.         allchoice += choice #choice是单次选择的商品列表,allchoice是所有选择的商品列表
  145.     while(1):
  146.         global total
  147.         total = 0
  148.         choiceSet = set(allchoice)#转换成集合,便于不重复计数
  149.         for it in choiceSet:
  150.             print(shop[it-1][0],shop[it-1][1],shop[it-1][2],'*',allchoice.count(it))
  151.             total += shop[it-1][2]*allchoice.count(it)*discount
  152.         print("总计:",total,"已优惠:",shop[it-1][2]*allchoice.count(it)*(1-discount))
  153.         print("---------------------------------\n"
  154.               "1:继续选购 2:整理购物车 3:结算\n")
  155.         option = int(input( "请选择:"))
  156.         if option == 1:
  157.             break
  158.         elif option == 2:
  159.             item_num = int(input("请输入要删除的商品"))
  160.             allchoice.remove(item_num)#每次只会删除一个元素
  161.             continue
  162.         else:
  163.             print("您需要支付的金额为:" , total)
  164.             score += total

  165. first_page()
  166. run = 1
  167. while run == 1:
  168.     if choice == 1:
  169.         log_in()
  170.         first_page()
  171.     elif choice == 2:
  172.         register()
  173.         first_page()
  174.     elif choice == 3:
  175.         check_score()
  176.         first_page()
  177.     elif choice == 4:
  178.         shopping()
  179.         first_page()
  180.     if choice == 5:
  181.         run -= 1
  182. if run == 0:
  183.     in_user.remove(user)
  184.     print("See u next time.")



  185.             
  186.             
  187.         
  188.    
  189.    
  190.                
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-12-8 14:01:17 | 显示全部楼层
input得到的choice是字符串
while run == 1:中判断的是整数,不会相等的。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-8 16:02:15 | 显示全部楼层
应该把这一句:

  1. choice = input("please enter your choice:")
复制代码


改成这样:

  1. choice = int(input("please enter your choice:"))
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-21 06:00

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表