根号1989 发表于 2017-12-20 22:05:45

小甲鱼老师26讲编写登录程序,这样编写有啥问题没有

contacts = dict()
while 1:
    print('\n|--- 新建用户:N/n ---|')
    print('|--- 登录账户:E/e ---|')
    print('|--- 推出程序:Q/q ---|')
    a = {'N','n','E','e','Q','q'}
    instr = input('|--- 请输入指令代码:')
    if instr in a:
      if instr == 'N' or instr == 'n':
            name = input('请输入用户名:')
            while name in contacts:
                print('此用户名已经被使用,', end='')
                name = input('请重新输入:')
                continue
            else:
                contacts = input('请输入密码:')
                print("注册成功,赶紧试试登录吧")      
      if instr == 'E' or instr == 'e':
            name = input('请输入用户名:')
            while name not in contacts:
                print('您输入的用户名不存在,', end='')
                name = input('请重新输入:')
                continue
            else:
                code = input('请输入密码:')
                while code != contacts:
                  code = input('密码错误,请输入密码:')
                  continue
                else:
                  print('欢迎进入系统,请点击右上角X结束程序')
            break
      if instr == 'Q' or instr == 'q':
            break
    else:
      print('输入指令有误')

BngThea 发表于 2017-12-20 22:20:43

逻辑没有什么问题
但是所有的continue和它下面的else都可以删掉,当然要调整一下缩进

根号1989 发表于 2017-12-21 19:29:04

BngThea 发表于 2017-12-20 22:20
逻辑没有什么问题
但是所有的continue和它下面的else都可以删掉,当然要调整一下缩进

恩,我试一下

根号1989 发表于 2017-12-21 19:33:08

根号1989 发表于 2017-12-21 19:29
恩,我试一下

怎么调整呢
页: [1]
查看完整版本: 小甲鱼老师26讲编写登录程序,这样编写有啥问题没有