本帖最后由 sunrise085 于 2020-4-27 00:24 编辑
你的程序在while循环中有个if…else…,在if和else中分别有break和continue进行跳转,所以第二个if '*' in str:根本不会执行。
第一个if '*' in str:是会执行的。
但是你的程序有个问题:若第一次输入的str有*的话,次数仍然会减一,因为你在第一次input之后没有判断是否有*就直接减一了。
此外,str是python的内置函数,也是一个类,最好不要用它做变量名
- correct = 'fishc.com'
- i = 3
- pro="Please input password:"
- while i > 0:
- str1 = input(pro)
- if correct == str1:
- print("welcome to my system!")
- print("Please wait......")
- break
-
- else:
- if '*' not in str1:
- i=i-1
- else:
- print("Please don't input * in password!")
- pro="Please input right password,you have %d chance:" % i
- continue
- else:
- print("You\'re no chance!")
- print("Goodbye!")
复制代码