程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Registration verification program for Python string cases

編輯:Python

About bloggers : Former Internet manufacturer tencent staff , Network security giant Venustech staff , Alibaba cloud development community expert blogger , WeChat official account java Quality creators of basic notes ,csdn High quality creative bloggers , Entrepreneur , Knowledge sharers , Welcome to your attention , give the thumbs-up , Collection .


One 、 background

Python Is an easy to learn 、 Powerful programming language . It provides an efficient high-level data structure , It's also a simple and effective way of object-oriented programming .Python Elegant grammar and dynamic typing and the essence of interpretive language , Make it an ideal language for scripting and rapid application development on most platforms . Now let's introduce python Through string related knowledge to achieve a simple registration verification program .


Two 、 actual combat

example : Write a registration verification program , Set the following conditions : (1) The user name must be underlined “_” start , The length must be in 3~30 Between characters ; (2) Password must be underlined 、 Numbers and letters make up , No other symbols are allowed , The length must be in 8~16 Between characters .

The code is as follows , Each line is explained in the notes .

user_name = input(" Please enter a user name ( With “_” start ,3-30 Characters ):")
password = input(" Please input a password ( By underline 、 Numbers and letters make up ,8-16 Characters ):")
if user_name[0] != '_': # If user_name The first character of is not “_”
print(" Please start the user name with an underscore ") # Output “ Please start the user name with an underscore ”
elif 3 > len(user_name) or 30 < len(user_name): # If user_name The length is less than 3 Or greater than 30
print(" User name length exceeds the limit ") # Output “ User name length exceeds the limit ”
elif 8 > len(password) or 16 < len(password): # If password The length is less than 8 Or greater than 16
print(" Password length exceeds the limit ") # Output “ Password length exceeds the limit ”
elif password.find('_') == -1: # If password Does not exist in the “_”
print(" No underscore was entered in the password ") # Output “ No underscore was entered in the password ”
else: # None of the above conditions are met
psswords = password.replace('_', '1') # take password Replace the underline in with 1
if psswords.isalnum(): # passwords Whether there are only numbers or letters in
print(" Congratulations , Registered successfully ! user name :", user_name, ", password :", password)
else: # passwords There are characters other than numbers or letters in
print(" There are other symbols in the password , Registration failed !") # Output “ There are other symbols in the password …”

adopt pycharm The results are as follows , You can copy the code to understand .


3、 ... and 、 Reference resources

1、 Liao Xuefeng's official website 2、python Official website 3、Python Programming case tutorial


Four 、 summary

That's about Python Through string related knowledge to achieve a simple registration verification program ., You can refer to it , Relevant knowledge will be continuously updated later , Make progress together .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved