wheil循环 for循环

wheil循环 登录密码用户只能输入3次

counter = 0 "定义开始次数"
_user = "wl"
_password = "aaa123"

while counter <3:

username = input("Username:")
password = input("password:")

if username == _user and password == _password:

print("wel come %s login" % _user)

break # 跳出 中断
else:
print("输入错误")
counter += 1
else:
print("超过3次输入")


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
用户输入3次错误可以按Y继续

counter = 0
_user = "wl"
_password = "aaa123"
while counter <3:
username = input("Username:")
password = input("password:")
if username == _user and password == _password:
print("wel come %s login" % _user)
break # 跳出 中断
else:
print("输入错误")
counter += 1
if counter ==3:
keep = input("继续请按Y")
if keep == "y":
counter=0
else:
print("超过3次输入")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
布尔运算

# (True) and (False) and 左右两边执行结果都是True 才为True真


# (True) or (False) or左右两边执行结果任意结果是True真 就为真

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

age= 50

flag= True

while flag:
user_input_age = int(input("请输入年龄:"))
if user_input_age == age:
print("输入正确")

elif user_input_age> age:
print("输入年龄过大")


else:
print("你输入年龄小于")

print("111")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

转载于:https://www.cnblogs.com/djkofwl/p/9448239.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值