日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

创建一个的用户

發布時間:2024/9/30 编程问答 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 创建一个的用户 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

《量化投資以python為工具》第九章作業第二題P109
輸入用戶名:首位必須為字母
輸入密碼:1.首位為字母
2.長度大于6
3.必須至少含有’_’或’*’或’#’中的一個
4.必須至少含有一個數字
代碼實現:

#方法一 def createuser():fuhao = ['_', '*', '#']while(1):print('input username:')username = input()if username[0] > 'a' and username[0] < 'z':breakelse:print('username must begin with a-z')while(1):print('input password:')password = input()if password[0] < 'a' or password[0] > 'z':print('password must begin with a-z')elif(len(password) <= 6):print('the length of password must upper 6')elif((fuhao[0] not in password) and (fuhao[1] not in password) \and (fuhao[2] not in password)):print('''password must at least include one of '_', '*', '#' ''')elif(('0' not in password) and ('1' not in password) and ('2' not in\password) and ('3' not in password) and ('4' not in password) and\('5' not in password) and ('6' not in password) and ('7' not in\password) and ('8' not in password) and ('9' not in password)):print('password must at least one number')else:print('create successful!')break #方法二 def createuser2():fuhao = ['_', '*', '#']while(1):print('input username:')username = input()if username[0] > 'a' and username[0] < 'z':breakelse:print('username must begin with a-z')while(1):print('input password:')password = input()if len(password) <= 6:print('the leghth of password must bigger than 6')err1 = 0err2 = 0for i in range(len(password)):if i == 0:if password[i] < 'a' or password[i] > 'z':print('password must begin with a-z')if password[i] in fuhao:err1 = 1if password[i] >= '0' and password[i] <= '9':err2 = 1if err1 == 0:print("""password must include at least one of '_', '*', '#'""")elif err2 == 0:print('password must at least include one of number')else:print('create successful!')break

沒有考慮大寫字母(懶得考慮了,也簡單,先將用戶名和密碼用lower()全部改為小寫字母再判斷就行)
之所以寫的這么麻煩是因為想要得到輸入具體不符合哪個要求。代碼有些冗余,大家隨時可以批評指正。

總結

以上是生活随笔為你收集整理的创建一个的用户的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。