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. 分析: 将长度为 ...
随机推荐
- nginx和apache作为webserver的差别
1.两者所用的驱动模式不同. nginx使用的是epoll的非堵塞模式事件驱动. apache使用的是select的堵塞模式事件驱动. 2.fastcgi和cgi的差别 当用户请求web服务的时候.w ...
- orale 中创建定时任务
--添加变量 variable job1 number; --创建JOB begin dbms_job.submit(:job1,'testjob;',sysdate, 'TRUNC(sysdat ...
- android开发游记:ItemTouchHelper 使用RecyclerView打造可拖拽的GridView
以下是RecyclerView结合ItemTouchHelper实现的列表和网格布局的拖拽效果. 效果图例如以下:(gif图有点顿卡,事实上执行是非常流畅的) demo下载地址: DragRecycl ...
- codeforces#281 A
脑子有点秀逗 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm ...
- rest_framework 视图
视图: a.过去 class PagerView(View): pass b.现在 class Pager1View(APIView): pass c.rest_framework 基本没用 from ...
- jqueryValidator自定义校验规则的一种方式(不覆盖源码)
1.封装自定义验证方法-validate-methods.js /***************************************************************** j ...
- Css border样式
1 四个边框 border-left 设置左边框,一般单独设置左边框样式使用border-right 设置右边框,一般单独设置右边框样式使用border-top 设置上边框,一般单独设置上边框样式使用 ...
- Monad的基本运算
A monad is created by defining a type constructor M and two operations, bind and return (where retur ...
- WebRTC Native APIs
WebRTC Native APIs The WebRTC Native APIs implementation is based on W3C’s WebRTC 1.0: Real-time Com ...
- 洛谷 P2542 [AHOI2005]航线规划 树链剖分_线段树_时光倒流_离线
Code: #include <map> #include <cstdio> #include <algorithm> #include <cstring&g ...