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. 三层登录—c#

    学习了三层,有一个登录窗口的小练习.是我们第一次接触三层的初战.如今仅仅是简单的了解了一些,须要学习的还有非常多,以下浅谈自己的理解. 我们说的三层就是分层了显示层.业务逻辑层和数据訪问层.当中显示层 ...

  2. 经常使用传感器协议1:CJ/T-188 水表协议解析1

          本文以实例说明CJ/T-188水表协议的解析过程,下面数据未经特殊说明,均指十六进制. 数据发送:         FE FE FE FE 68 10 44 33 22 11 00 33 ...

  3. HDU 4930 Fighting the Landlords(暴力枚举+模拟)

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

  4. POJ 1012 Joseph(打表题)

    题意:约瑟夫环的变形.要求寻找到一个杀人循环节m使后半节的坏人先被所有杀光. 直接链表模拟出结果,再打表即可: 代码:(凝视的是打表码) #include<iostream> #inclu ...

  5. JAVA输出带BOM的UTF-8编码的文件

    当从http 的response输出CSV文件的时候,设置为utf8的时候默认是不带bom的,可是windows的Excel是使用bom来确认utf8编码的,全部须要把bom写到文件的开头. 微软在 ...

  6. angularjs 模块化

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  7. Android开发之Volley网络通信框架

    今天用了一下Volley网络通信框架,感觉挺好用的,写个博客记录一下用法.方便以后VC. Volley(Google提供的网络通信库,能使网络通信更快,更简单,更健壮.) 功能模块: 1. JSON, ...

  8. void指针 (补充)

    void* 表示空指针.空指针不能直接使用,比如,指针的加减法操作(由于不知道类型,无法确定偏移的大小).某些情况下.不知道指针的类型,先用void*来取代,依据须要再强制转换成须要的指针类型使用. ...

  9. ProFTPD 的 mod_lang模块

    ProFTPD 的 mod_lang模块http://www.proftpd.org/docs/modules/mod_lang.html安装该mod_lang模块随ProFTPD一起分发.要在pro ...

  10. zzulioj--1816--矩形(好题数学)

    1816: 矩形 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 88  Solved: 24 SubmitStatusWeb Board Descri ...