python code 1_username registration & login
This tiny program consists of 2 parts - registration and login. In the part of registration, the key point is to create a folder to store user's information. And the part that cost my most time is how to name a file automatically with variety's name. Here is the registration code:
# Author: Eva Han for i in range(1000):
r_username = input('please input your username for registration:')
r_passwd = input('please input your password for registration:')
r_passwd2 = input('please input your password again:') if r_passwd == r_passwd2:
file_name = 'F:/python/计算机学习/practice/homework1/registration/'+ r_username +'.txt'
regis_info = open(file_name,'w+')
regis_info2 = '''{_r_username}
{_r_passwd}'''.format(_r_username = r_username, _r_passwd = r_passwd )
regis_info.write(regis_info2 )
regis_info.flush()
regis_info.close()
break
else:
print('The passwords are diffrent, please input again')
Besides, there is a small point needed to be paid attention to - the content of regis_info2. Don't add any blank space!!! It's pretty important! and we need to check it again and again. Cuz in the next part, because of the blank space that I didn't notice, I was reminded that I input a wrong password many times even if I input the right one. = ^ =
In the login program, the best parts are the methods of globaling a variety, reading the content in a specific line and using count number to operate under a specific condition. The login program is shown below:
# Author: Eva Han
username = input('Please input your username for login:')
user_file_name = 'F:/python/计算机学习/practice/homework1/registration/'+ username +'.txt'
user_info = open(user_file_name, 'r')
# 读取第二行的信息,并存为_password变量
# lines = user_info.readlines()
# line2 = user_info.readline()
def func():
count = 0
global l_passwd
for lines in user_info:
count = count + 1 # 此处的起始值即为1
if count == 2:
l_passwd = lines
break
func()
# 让用户输入密码进行判断
count2 = 0
for j in range(3):
password = input('please input your password for login:')
if l_passwd == password:
print('Welcome to my world!')
break
else:
print('wrong password!')
count2 += 1
if count2 == 3:
print('Your account is locked...')
l_file_name = 'F:/python/计算机学习/practice/homework1/login/'+username+'.txt'
login_info = open(l_file_name,'w+')
login_info.write(username)
login_info.close()
------------------------------------------------------------------------------------------------------END----------------------------------------------------------------------------------------------------------------------------------------------------------------
python code 1_username registration & login的更多相关文章
- Exploring Python Code Objects
Exploring Python Code Objects https://late.am/post/2012/03/26/exploring-python-code-objects.html Ins ...
- 机器学习算法实现(R&Python code)
Machine Learning Algorithms Machine Learning Algorithms (Python and R) 明天考试,今天就来简单写写机器学习的算法 Types Su ...
- How to run Python code from Sublime
How to run Python Code from Sublime,and How to run Python Code with input from sublime Using Sublime ...
- Python code 提取UML
Python是一门支持面向对象编程的语言,在大型软件项目中,我们往往会使用面向对象的特性去组织我们的代码,那有没有这样一种工具,可以帮助我们从已有代码中提取出UML图呢?答案是有的.以下,我们逐个介绍 ...
- PEP 8 – Style Guide for Python Code
原文:PEP 8 – Style Guide for Python Code PEP:8 题目:Python代码风格指南 作者:Guido van Rossum, www.yszx11.cnBarry ...
- Change the environment variable for python code running
python程序运行中改变环境变量: Trying to change the way the loader works for a running Python is very tricky; pr ...
- python code
执行动态语句 执行字符串中的代码 http://www.cnblogs.com/fanweibin/p/5418817.html #!usr/bin/env python #coding:utf-8 ...
- Python——Code Like a Pythonista: Idiomatic Python
Code Like a Pythonista: Idiomatic Python 如果你有C++基础,那学习另一门语言会相对容易.因为C++即面向过程,又面向对象.它很底层,能像C一样访问机器:它也很 ...
- python code practice(二):KMP算法、二分搜索的实现、哈希表
1.替换空格 题目描述:请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 分析: 将长度为 ...
随机推荐
- ios 将随意对象存进数据库
要将一个对象存进数据库的blob字段,最好先转为NSData.一个对象要遵守NSCoding协议,实现协议中对应的方法,才干转成NSData. NSData *statusData = [NSKeye ...
- QTP11.5公布,改名UFT
QTP11.5公布,改名UFT,支持多脚本编辑调试.PDF检查点.持续集成系统.手机測试等 http://www.learnqtp.com/hp-uft11-5-qtp-new-features/ T ...
- matplotlib 可视化 —— 定制 matplotlib
1. matplotlibrc 文件 matplotlib使用matplotlibrc [matplotlib resource configurations] 配置文件来自定义各种属性,我们称之为 ...
- 2.IntelliJ IDEA 2017创建JavaEE项目
转自:https://blog.csdn.net/qq_31628285/article/details/75139909?utm_source=blogxgwz0 IntelliJ IDEA 201 ...
- [Project Euler 409] Nim Extreme 解题报告 (统计方案数)
题目链接:https://projecteuler.net/problem=409 题目: 题解: 题目问你必胜态的数目,我们考虑用总的方案数减去必败态的方案数(NIM游戏没有平局这个操作) 必败态的 ...
- POJ 4007 Flood-it!
题目:http://poj.org/problem?id=4007 思路: (lyd学长的思路) IDA*算法,首先迭代加深限制搜索深度. 可以发现如果当前矩阵中除了左上角的连通块之外,共有M种颜色, ...
- PostgreSQL Replication之第九章 与pgpool一起工作(2)
9.2 理解pgpool的功能 pgpool提供了如下功能: •连接池 •语句级别的复制 •负载均衡 •限制连接 •内存缓存 •并行查询 [当决定使用那些功能的时候,记住并非所有的功能可以在同一时间使 ...
- 解决mongodb TypeError: Cannot read property 'XXX' of null 问题
有时候我们的字段里的数据为空而去查询就会报错. 比如以下形式: “cartList”:[] “cartList”:[{}] “cartList”:{} “cartList”:null 在查询的时候加上 ...
- 紫书 习题 10-13 UVa 11526(打表找规律+分步枚举)
首先看这道题目,我预感商数肯定是有规律的排列的,于是我打表找一下规律 100 / 1 = 100 100 / 2 = 50 100 / 3 = 33 100 / 4 = 25 100 / 5 = ...
- shiro整合thymeleaf
1.引入依赖 <!--thymeleaf中使用shiro--> <dependency> <groupId>com.github.theborakompanioni ...