第9节:回顾用户交互、循环例句
1)使用raw_input、while函数写出用户交互
#!/usr/bin/env python
import sys
username = 'strom'
password = '123456'
locked = 0
retry_counter = 0
while retry_counter<3:
user = raw_input('Username:').stript()
if len(user) == 0:
print '\033[31;1mUsername cannot be empty!\033[0m'
continue
passwd = raw_input('Password:').stript()
if len(passwd) == 0:
print '\033[31;1mPassword cannot be empty!\033[0m'
continue
#going to the loging verification part
if locked == 0:
print 'Your username is locked!'
sys.exit()
else:
if user == username and passwd == password:
#means passed the verfification
sys.exit('Welcome %s login to our system!' % user)
else:
retry_counter += 1
print '\033[31;1mWrong username or password,you have %s more chances!\033[0m' % (3-retry_counter)
1)使用raw_input、while函数写出用户交互
#!/usr/bin/env python
import sys
username = 'strom'
password = '123456'
locked = 0
retry_counter = 0
while retry_counter<3:
user = raw_input('Username:').stript()
if len(user) == 0:
print '\033[31;1mUsername cannot be empty!\033[0m'
continue
passwd = raw_input('Password:').stript()
if len(passwd) == 0:
print '\033[31;1mPassword cannot be empty!\033[0m'
continue
#going to the loging verification part
if locked == 0:
print 'Your username is locked!'
sys.exit()
else:
if user == username and passwd == password:
#means passed the verfification
sys.exit('Welcome %s login to our system!' % user)
else:
retry_counter += 1
print '\033[31;1mWrong username or password,you have %s more chances!\033[0m' % (3-retry_counter)