#######练习题#######
# print(‘1、使用while循环打印输入 1 2 3 4 5 6 8 9 10‘)
# num = 1
# while num <= 10:
# if num == 7:
# num = num + 1
# continue
# else:
# print(num)
# num += 1
######################################################
#2、打印1-100所有数的和
# sum = 0
# count = 1
# while count < 101:
# sum = sum + count
# count = count + 1
# print(sum)
#3、输出1-100内所有的奇数
#for i in range(100):
# if i % 2 == 1:
# print(i)
#4、输出1-100内所有的偶数
#for i in range(100):
# if i % 2 == 0:
# print(i)
# #5、打印1-2+3-4+5....+99所有数的和
# sum = 0
# for i in range(1,100):
# if i % 2 == 0:
# sum = sum - i
# elif i % 2 == 1:
# sum = sum + i
# print(sum)
#6、用户登录(3次机会重试)
#第一种普通方式:
li = [{‘username‘:‘alex‘,‘password‘:‘SB‘},{‘username‘:‘wusir‘,‘password‘:‘sb‘},{‘username‘:‘taibai‘,‘password‘:‘男神‘}]
i = 0
while i < 3:
name = input(‘请输入用户名:‘)
pwd = input(‘请输入密码:‘)
if name == ‘alex‘ and pwd == ‘SB‘:
print(‘登录成功‘)
break
elif name == ‘wusir‘ and pwd == ‘sb‘:
print(‘登录成功‘)
break
elif name == ‘taibai‘ and pwd == ‘男神‘:
print(‘登录成功‘)
break
else:
print(‘用户名和密码错误,你还有%s次机会‘ % (2-i))
i = i + 1
if i == 3:
choice = input(‘你是否还想再试试?Y‘)
if choice == ‘Y‘:
i = 0
else:
print(‘还要脸吗?‘)
#第二种方式:
li = [{‘username‘:‘alex‘,‘password‘:‘SB‘},{‘username‘:‘wusir‘,‘password‘:‘sb‘},{‘username‘:‘taibai‘,‘password‘:‘男神‘}]
sum = 0
while sum < 3:
name = input(‘请输入用户名:‘)
pwd = input(‘请输入密码:‘)
for i in li:
if name == i[‘username‘] and pwd == i[‘password‘]:
print(‘登录成功‘)
sum = sum + 3
break
else:
print(‘用户名和密码错误,你还有%s次机会‘ % (2-sum))
sum = sum + 1
if sum == 3:
choice = input(‘你是否还想再试试?Y‘)
if choice == ‘Y‘:
sum = 0
else:
print(‘还要脸吗?‘)