1. 程式人生 > >day1_字符集,流程控制語句

day1_字符集,流程控制語句

pre 字符集 locked rto 鎖定 bre tac 菜單 break

作業1:

  • 輸入用戶名密碼
  • 認證成功後顯示歡迎信息
  • 輸錯三次後鎖定

解答:

  流程圖:

  技術分享

  代碼:

 1 #!/usr/bin/env python
 2 # *_* coding:utf-8 *_*
 3 # python learning, keep on!
 4 count=0
 5 while count <3:
 6     username = input(username:)
 7     password = input(password:)
 8     userlock=[]
 9     for i in open(lockuser.txt,r
): 10 userlock.append(i.strip(\n)) 11 if username in userlock: 12 print(your username has locked! please contact administrator.) 13 break 14 else: 15 user=[] 16 for j in open(user.txt,r): 17 user.append(j.strip(\n)) 18 up=username+
:+password 19 if up in user: 20 print(wellcome +username+ login!!) 21 break 22 else: 23 count+=1 24 print(Invalid username or password, your try +str(count)+ times) 25 else: 26 print(too many time you try ,we locking your username.
) 27 usertolock=open(lockuser.txt,a) 28 usertolock.write(username+\n) 29 usertolock.close()

作業二:

  • 三級菜單
  • 可一次選擇進入各子菜單
  • 所需新知識點:列表、字典

解答

  流程圖

  代碼

day1_字符集,流程控制語句