Python-Day01-task

Day01课后作业

1、作业要求

     编写登录接口

     -输入用户名密码

     -认证成功后显示欢迎信息

     -输错三次后退出

2、流程图

3、程序

#!/usr/bin/env python

f = open("foo.txt")       #打开用户密码文件
line = f.readline()       #读取用户名
line1= f.readline()       #读取密码
f.close()                 #关闭文件

i =1
while i <= 3:
  input_name = raw_input("Please input your name:")
  input_passwd = raw_input("Please input  your passwd:")
  if input_name == line[:-1]:         #[:-1]的作用是去掉换行符
     if input_passwd == line1[:-1]:
        print "Wecome to linux world,login successfully!"
        break
     else:
        print "you input the passwd is wrong"
  else:
     print "you input the name is wrong"
  i += 1
else:
  print "you haved try 3 times,no time to try today!!!"
[xiaorui@xiaorui day01]$ cat foo.txt 
ruizhong.li
passwd

4、课上练习程序(待优化)

#!/usr/bin/env python
#_*_ coding:utf-8 _*_     #添加此行后,就可以输中文了

print_num = input('Which loop do you want it to be printed out?')
count = 0
while count < 10000000:
  if count == print_num:
     print 'There you got the number:',count
     choice = raw_input('Do you want to continue the loop?(y/n)')
     if choice == 'n':
        break
     else:
        while print_num <= count:
              print_num = input('Which loop do you want it to be printed out?')
              if print_num > count:
                 break
              else:
                 print u'已经过了,sx!'
  else:
     print 'Loop:',count
  count +=1
else:
  print 'loop:',count

 

posted @ 2016-03-06 19:45  幻月0412  阅读(187)  评论(0编辑  收藏  举报