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的更多相关文章

  1. Exploring Python Code Objects

    Exploring Python Code Objects https://late.am/post/2012/03/26/exploring-python-code-objects.html Ins ...

  2. 机器学习算法实现(R&Python code)

    Machine Learning Algorithms Machine Learning Algorithms (Python and R) 明天考试,今天就来简单写写机器学习的算法 Types Su ...

  3. 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 ...

  4. Python code 提取UML

    Python是一门支持面向对象编程的语言,在大型软件项目中,我们往往会使用面向对象的特性去组织我们的代码,那有没有这样一种工具,可以帮助我们从已有代码中提取出UML图呢?答案是有的.以下,我们逐个介绍 ...

  5. PEP 8 – Style Guide for Python Code

    原文:PEP 8 – Style Guide for Python Code PEP:8 题目:Python代码风格指南 作者:Guido van Rossum, www.yszx11.cnBarry ...

  6. 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 ...

  7. python code

    执行动态语句 执行字符串中的代码 http://www.cnblogs.com/fanweibin/p/5418817.html #!usr/bin/env python #coding:utf-8 ...

  8. Python——Code Like a Pythonista: Idiomatic Python

    Code Like a Pythonista: Idiomatic Python 如果你有C++基础,那学习另一门语言会相对容易.因为C++即面向过程,又面向对象.它很底层,能像C一样访问机器:它也很 ...

  9. python code practice(二):KMP算法、二分搜索的实现、哈希表

    1.替换空格 题目描述:请实现一个函数,将一个字符串中的每个空格替换成“%20”.例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 分析: 将长度为 ...

随机推荐

  1. OpenCASCADE License FAQs

    OpenCASCADE License FAQs 经常用人问我使用OpenCASCADE开发商业软件是否需要付费,下面从OpenCASCADE的官方网站上截取其回答翻译成中文,官方网址:https:/ ...

  2. action support分析

    Action这一部分主要是数据(索引)的操作和部分集群信息操作. 所有的请求通过client转发到对应的action上然后再由对应的TransportAction来执行相关请求.如果请求能在本机上执行 ...

  3. 数位$dp$

    数位\(dp\)搞了一上午才搞懂.靠这种傻\(X\)的东西竟然花了我一上午的时间. 数位\(dp\) 概念 数位\(dp\)就是强制你分类一些数,例如给你一段区间,然后让你求出不包含\(2\)的数的个 ...

  4. spring mvc给参数起别名

    需求: 将http报文请求(保护body和url)中的参数传递给Controller时支持使用别名. 举例: 下面两条请求报文的结果是一致的. http://example.com/foo?jobTy ...

  5. childNodes.length和form.length的不同

    我们知道,DOM里面提供了element.childNodes.length属性,childNodes 属性返回节点的子节点集合,以 NodeList 对象. 那么childNodes包含哪些节点呢? ...

  6. 用fcntl锁一个文件来保护操作

    int testfd; /* fd for test*/ if((testfd = open("/usr/local/pgsql/bin/test_fd",O_RDWR|O_CRE ...

  7. 如何知道 CPU 是否支持虚拟化技术(VT)

    作者: Sk 译者: LCTT geekpi 我们已经知道如何检查你的 Linux 操作系统是 32 位还是 64 位以及如何知道你的 Linux 系统是物理机还是虚拟机.今天,我们将学习另一个有用的 ...

  8. linux安装memcacehed

        1.wget http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz     2.wget http://www.monkey.o ...

  9. NodeJS学习笔记 (22)全局对象-global

    https://github.com/chyingp/nodejs-learning-guide

  10. 洛谷3857 [TJOI2008]彩灯

    题目描述 已知一组彩灯是由一排N个独立的灯泡构成的,并且有M个开关控制它们.从数学的角度看,这一排彩灯的任何一个彩灯只有亮与不亮两个状态,所以共有2N个样式.由于技术上的问题,Peter设计的每个开关 ...