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. 分析: 将长度为 ...
随机推荐
- vim水平摆放全部窗体的三个方法
Method1: map <F7> <ESC>:windo exe "normal \<foobar<C-W>C-W>K"<C ...
- 好记性不如烂笔头86-spring3学习(7)-ApplicationContext中bean的生命周期
假设使用ApplicationContext来生成.管理Bean, 一个Bean从建立到销毁,会历经几个运行阶段. 我个人理解一般的bean的生命周期主要包含:建立,初始化,使用阶段,销毁四个核心阶段 ...
- css实现上下左右布局
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- POJ 3256 Cow Picnic
Cow Picnic Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4928 Accepted: 2019 Descri ...
- 42.angularJS自定义服务
转自:https://www.cnblogs.com/best/tag/Angular/ 1. 你可以创建自定义服务,链接到你的模块中: <!DOCTYPE html> <html& ...
- rest_framework-序列化-总结完结篇
#rest_framework 序列化 from rest_framework import serializers #serilizers.Serializer serializers.ModelS ...
- Linux中的find命令
.递归查找(find 命令 是递归遍历文件夹的) 命令:find . -name “*.txt” //当前路径下递归查找以.txt结尾的文件夹 .不递归查找 find . -name “*.txt” ...
- react --- React中state和props分别是什么?
props React的核心思想就是组件化思想,页面会被切分成一些独立的.可复用的组件. 组件从概念上看就是一个函数,可以接受一个参数作为输入值,这个参数就是props,所以可以把props理解为从外 ...
- HikariCP--一款高性能的 JDBC 连接池
源码地址:https://github.com/brettwooldridge/HikariCP 使用方法: Java 8 maven artifact: <dependency> < ...
- 使用NiftyModeEffects对话框
最近看到一篇有关个性对话框的文章,里面介绍了非常酷的动画效果,开源的项目下载来试试,用法很简单. NoftyDialogEffects效果参考: http://tympanus.net/D ...