1.计算 1 - 2 + 3 ...99中除了88以外所有数的总和
sum = 0
count = 1
flag = -1
while count <= 99:
flag *= -1
if count == 88:
count += 1
continue
sum = sum + count * flag
count += 1
print(sum)
2.用户登录(三次重试机会)假设密码账户均为admin(完善版)
count = 3
while True :
user = input("请输入账号")
password = input("请输入密码")
if user == "admin" and password == "admin" :
msg = '''恭喜您登录成功
用户名:%s
密 码:%s
'''%(user,password)
print(msg)
break
else:
count -= 1
if count!=0:
print("你还有", count, "次机会")
flag = input("是否继续输入y/n")
if flag != 'y':
print("登录失败")
break
else :print("请继续输入")
else:
print("登录失败")
print("机会已经用完,下次见")
break