简单的口令检查程序 按下述要求编写口令检查程序(假设正确的口令为8888,正确口令"8888"为字符串)。 (1)若输入口令正确,则提示"You are welcome!\n",程序结束。输入口令的提示信息为:"Please enter password:" (2)若输入口令不正确,则提示"Wrong password!\n",同时检查口令是否已输入3次,若未输入3次,则提示"Pleaseenter again:",且允许用户再次输入口令;若已输入3次,则提示"You have entered three times!You are not welcome!\n",且不允许用户再输入口令,程序结束。 程序运行示例1: Please enter password:123456 Wrong password! Please enter again:2345 Wrong password! Please enter again:1357 Wrong password! You have entered three times!You are not welcome! 程序运行示例2: Input Password:8888 You are welcome!
时间: 2024-02-03 17:03:59 浏览: 74
以下是口令检查程序的Python代码:
```python
password = "8888"
count = 0
while count < 3:
input_password = input("Please enter password:")
if input_password == password:
print("You are welcome!")
break
else:
print("Wrong password!")
count += 1
if count < 3:
print("Please enter again:")
else:
print("You have entered three times! You are not welcome!")
```
程序首先定义了正确的口令为字符串"8888",并且设置了计数器count为0。然后使用while循环,检查口令是否正确。如果输入的口令与正确的口令一致,程序会输出"You are welcome!"并结束。如果输入的口令不正确,计数器count会加1,同时判断count是否达到了3次。如果还未达到3次,程序会输出"Wrong password!"和"Please enter again:",并继续等待用户输入口令。如果已经输入了3次,程序会输出"You have entered three times! You are not welcome!"并结束。