hsjs1002 发表于 2017-5-4 14:54:33

登陆系统

user={}
def main():
    while True:
      print('|---New user:N/n---|')
      print('|---login in:E/e---|')
      print('|---Quit: Q/q ---|')
      command=input('|---Plese enter the conmmand:')
      if command == 'n' or 'N':
            register()
      elif command == 'e' or 'E':
            login_in()
            

      elif command == 'Q' or 'q':
            qt()
      else:
            print('Please enter the right command .')
            continue








def register():
    name=input('Please enter the user\'s name:')
    if name in user:
      print('This name has been used,please try another one.')
    else:
      password=input('Please enter the password:')
      user=password
      print('Registration succeed, try to login in^_^')

def login_in():
    name1=input('Please enter your name:')
    if name not in user:
      name=input('The name you entered does not exiset,please try again:')
    else:
      password=input('Please enter your password:')
      pwd=user.get(name)
      if pwd == password:
            print('Welcome to this system.')
      else:
            print('The password is not correct.')
def qt():
    print('You have quited the system, hope your next visit.')

main()
   
            


   
求助各位大神    错误在哪,现在新建用户的时候,不管输入的指令是不是n或N,程序都会进行下一步

新房客 发表于 2017-5-4 17:50:17

本帖最后由 新房客 于 2017-5-4 17:54 编辑

if command == 'n' or 'N' 相当于 if command == ‘n’or if 'N'
所以它总是对的,然后会执行register()。应当修改为:if (command == 'n') or (command == 'N')
页: [1]
查看完整版本: 登陆系统