python的第一个程序

2021/12/12 11:17:17

本文主要是介绍python的第一个程序,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#1、验证输入账号密码的正确性
username = "cwb"
password = "123456"
_user = input("请输入账号:")
_passwd = input("请输入密码:")
if _user == username and _passwd == password:
    print("login in sucess!!,welcome!!")
else:
    print("failed!!")
#2、尝试3次输入账号密码,输入3次后程序退出
username = "cwb"
password = "123456"
for i in range(3):
    _user = input("请输入账号:")
    _passwd = input("请输入密码:")
    if _user == username and _passwd == password:
     print("login in sucess!!,welcome!!")
     break
    else:
     print("failed!!")
#3、输入3次后提示 输入已达到上限,程序退出
username = "cwb"
password = "123456"
count = 0
for i in range(4):
   if count == 3:
     print("尝试此数已达上限,程序退出!!!!")
     break
   user = input("请输入账号:")
   passwd = input("请输入密码:")
   if user == username and passwd == password:
        print("login in sucess!!,welcome!!")
        break
   else:
          print("failed!!")
   count += 1
#4、输入3次后提示 输入已达到上限,输入Y继续,输入N退出
username = "cwb"
password = "123456"
count = 0
for i in range(10):
   if count == 3:
        msg = input("继续输入Y,退出输入N:")
        if  msg == "Y":
            count = 0
        else:
            print("尝试此数已达上限,程序退出!!!!")
            break
   user = input("请输入账号:")
   passwd = input("请输入密码:")
   if user == username and passwd == password:
        print("login in sucess!!,welcome!!")
        break
   else:
          print("failed!!")
   count += 1


这篇关于python的第一个程序的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程