欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python基本循环实例Day 1

程序员文章站 2024-03-30 21:44:57
输入正确的用户名和密码,显示登陆界面,超过三次输入错误则锁定,定义字符串记得加上单引号,数字可以int定义,while循环和if循环语句后加上:,break不加: ......

  输入正确的用户名和密码,显示登陆界面,超过三次输入错误则锁定,定义字符串记得加上单引号,数字可以int定义,while循环和if循环语句后加上:,break不加:

print("---------welcome to memory card hotel!-------")
_username = 'wryyy'
_password = 123
count = 0
while count <3:
username = input("username:")
password = int(input("password:"))
if _username == username and _password == password:
print("logining now...welcome {name}!".format(name = _username))
break
else:
print("invalid username or password.")
count = count +1
else:
print("locked on,you have tried too many times.")