一:输出100以内的奇数:
for i in range(0,100):
if i % 2 ==1:
print(i)
for i in range(1,100,2):
print(i)
二:输出100以内小于50大于70的数
for i in range(0,100):
if i < 50 or i > 70:
print('loop: ',i)
三:判断输入的用户名和密码,最多输入三次
_user = 'admin'
_passwd = '123'
for i in range(3):
username = input('Username: ')
password = input('Password: ')
if username == _user and password == _passwd:
print('Welcome %s login' % _user)
break
else:
print('Invalid Username or Password')
_user = 'admin'
_passwd = '123'
passed_autheneication = True
for i in range(3):
username = input('Username: ')
password = input('Password: ')
if username == _user and password == _passwd:
print('Welcome %s login' % _user)
passed_autheneication = False
break
else:
print('Invalid Username or Password')
if passed_autheneication:
print('操作过于频繁')
_user = 'admin'
_passwd = '123'
for i in range(3):
username = input('Username: ')
password = input('Password: ')
if username == _user and password == _passwd:
print('Welcome %s login' % _user)
break
else:
print('Invalid Username or Password')
else:
print('操作过于频繁')
_user = 'admin'
_passwd = '123'
i = 0
while i < 3:
username = input('Username: ')
password = input('Password: ')
if username == _user and password == _passwd:
print('Welcome %s login' % _user)
break
else:
print('Invalid Username or Password')
i += 1
if i == 3:
keep_going_chioce = input("还想继续吗?【Y/N】")
if keep_going_chioce =='Y':
i = 0