Python-Day01-task

Posted 幻月0412

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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!!!"
[[email protected] 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

 

以上是关于Python-Day01-task的主要内容,如果未能解决你的问题,请参考以下文章

python-day02-study

自学Python-Day1.1

python-day97--git协同开发

Python-day01

python-day 1

python-day01