Python 判断输入的用户名和秘码是不是正确
<div style="color: black; text-align: left; margin-bottom: 10px;">
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/pgc-image/676f137dc6a5433ba47794b8e1ab15b3~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1723900443&x-signature=8MW2vqLQCbQKNVqY7%2BYZeNEyLwA%3D" style="width: 50%; margin-bottom: 20px;"></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">题目: <span style="color: black;">运用</span> Python 语言编写一段代码, 实现用户输入用户名和<span style="color: black;">秘码</span>, 当用户名为 seven 且 <span style="color: black;">秘码</span>为 123 时, <span style="color: black;">表示</span>登陆成功, 否则登陆失败, 失败时<span style="color: black;">准许</span>重复输入三次。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"># !/usr/bin/python</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"># -*- coding: UTF-8 -*-</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">def main():</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">count = 0</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">while count < 3 :</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">username = str(input("Enter username:\n"))</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">passwd = str(input("Enter passwd:\n"))</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">if username.lower() == seven and passwd.lower() == 123:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">print("恭喜你! 登录成功")</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">break</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">else:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">if (2 - count) == 0:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">print("对不起, 你输入用户名和<span style="color: black;">秘码</span>的错误次数<span style="color: black;">已然</span>超过3次,请稍后再试<span style="color: black;">或</span>联系<span style="color: black;">咱们</span>的工作人员")</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">break</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">print("很遗憾! 你输入的用户名<span style="color: black;">或</span><span style="color: black;">秘码</span>错误")</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">print("您还有%d次机会再次正确的输入用户名和<span style="color: black;">秘码</span>" %(2 - count))</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">count += 1</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">if __name__ == __main__:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">main()</p>
</div>
顶楼主,说得太好了! 楼主发的这篇帖子,我觉得非常有道理。 你的见解真是独到,让我受益匪浅。 我完全同意你的观点,说得太对了。 我完全同意你的看法,期待我们能深入探讨这个问题。
页:
[1]