码迷,mamicode.com
首页 > 其他好文 > 详细

循环判断以及文件的使用--练习1

时间:2018-10-26 19:34:14      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:color   数据   else   ...   password   col   \n   username   port   

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author "Sniper"

import getpass
import os

### Registry Account   注册用户,将用户数据存入文件中

print("Welcome to the Registry System!\n\n\n")

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 !\n")
        print("You lose 1 chance , Now you have {counts} chances\n".format(counts=count -1))
    count -= 1
    if count == 0 :
        print("Uh-huh !!! You have been used up Your chances. Your account will be locked!!!\n")
        exit()
usr.close()
psd.close()

 

循环判断以及文件的使用--练习1

标签:color   数据   else   ...   password   col   \n   username   port   

原文地址:https://www.cnblogs.com/Sniper-tech-share/p/9857829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!