|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
password = list(input("please input your password: "))
times = 3
i = 0
length = len(password)
realpassword = list("chen")
while password[i] == "*" and i <= length:
password = list(input("密码中不能含有“*”号,你还有",times,"次机会,请输入密码:"))
while times > 0 and password != realpassword:
times -= 1
password = list(input("密码错误,你还有",times,"次机会:"))
if password == realpassword:
print("密码正确,进入程序。。。")
else:
print("密码错误,机器锁死")
运行程序后是这样
please input your password: 123456
Traceback (most recent call last):
File "D:/python/009-01.py", line 10, in <module>
password = list(input("密码错误,你还有",times,"次机会:"))
TypeError: input expected at most 1 argument, got 3
>>>
input 里面用格式化,你不能直接 , 逗号隔开,不然 Python 会认为你传入 3 个参数给 input 函数了,而 input 函数只能接受一个参数导致报错
正确代码,使用 字符串格式化即可,这里用 % 格式化:
- password = list(input("please input your password: "))
- times = 3
- i = 0
- length = len(password)
- realpassword = list("chen")
- while password[i] == "*" and i <= length:
- password = list(input("密码中不能含有“*”号,你还有%s次机会,请输入密码:"%times))
- while times > 0 and password != realpassword:
- times -= 1
- password = list(input("密码错误,你还有%s次机会:"%times))
- if password == realpassword:
- print("密码正确,进入程序。。。")
- else:
- print("密码错误,机器锁死")
复制代码
|
|