循环判断以及文件的使用--练习1
Posted sniper-tech-share
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了循环判断以及文件的使用--练习1相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author "Sniper" import getpass import os ### Registry Account 注册用户,将用户数据存入文件中 print("Welcome to the Registry System! ") username = input("Please Input Your UserName:") password = input("Please Input Your Password:") password2 = input("Please Verify Your Password:") if password == password2 : userfile = open("username.txt", "w+", encoding="UTF-8") passfile = open("password.txt", "w+", encoding="UTF-8") userfile.write(username) passfile.write(password) userfile.flush() passfile.flush() userfile.seek(0) passfile.seek(0) userfile.close() passfile.close() else: print("Your Password Is Not Matched ,Check Your Input!") exit() cls = os.system("cls") ####Login System 登录用户,判断登录信息是否正确 usr = open("username.txt") psd = open("password.txt") UserName = usr.read() PassWord = psd.read() count = 3 while True : print("++++++++++++++++++++++++++++++++++++++") print("+++ Welcome To The Alauda System +++") print("++++++++++++++++++++++++++++++++++++++") yourusername = input("Please input your username:") yourpassword = input("Please Input your password:") if UserName == yourusername and PassWord == yourpassword : print("Welcome {name} login ...".format(name=username)) break else : print("Please input the true username or password ! ") print("You lose 1 chance , Now you have {counts} chances ".format(counts=count -1)) count -= 1 if count == 0 : print("Uh-huh !!! You have been used up Your chances. Your account will be locked!!! ") exit() usr.close() psd.close()
以上是关于循环判断以及文件的使用--练习1的主要内容,如果未能解决你的问题,请参考以下文章
关于循环和数组的练习 - 使用循环 1 次以及如何获取数组的最大值