#encoding: utf-8#1. Implement user input user name and password, when the user name is seven and password is 123 , the login is successful, otherwise the login fails!name=input (' Name >>: '). Strip () password=input (' passwd>>: '). Strip () if name== ' seven ' and password== ' 123 ': print (' login successful ') else: print (' Login failed ') #2. Implement user input user name and password, when the user name is seven and password is 123 , the login is successful, otherwise the login fails, and the failure allows repeated input three times n =0while n < 3: name=input (' name>>: '). Strip () password=input (' passwd>>: '). Strip () if name== ' seven ' and password== ' 123 ': print (' login successful ') else: print (' login failed ') n+=1#3. Implement user input username and password, when user name is seven or alex and password is 123 when the login is successful,Otherwise, the login fails, allowing repeated input three times n=0while n < 3: name=input (' name>>: ') when failed. Strip () passwd=input (' passwd>>: '). Strip () if name== ' seven ' or name== ' Alex ' and passwd== ' 123 ': Print (' login successful ') else: Print (' login failed ') n += 1#8.a Using a while loop to implement output 2-3+4-5+6...+100 and n=2sum=0while n <= 100: if n%2==0: sum+=n else: sum-=n n+=1print (sum) #b. Using while loops for output 1,2,3,4,5, 7,8,9, 11,12 use while loop to implement all odd encoding:utf-8n=1while in output 1-100 n <= 12: if n==6 or n==10: n+=1 continue print (n) n+=1 #b. Use while loop to achieve all odd n=1while n<=100: if n in output 1-100 %2 !=0: print (n) n+=1#e. Using while Loop realizes all even n=1while n<=100: if n%2==0 in the output 1-100 : print (n) n+=1#9 The following two variables are available, please describe n1 What is the relationship between and n2 ? # n1 = 123456# n2 = n1# print (ID (N1)) # Print (n2) #关系: The same value, the same ID # 2 job: Write the Login interface ## Basic requirements:## Let the user enter the user name Password # authentication successful display welcome message # After three errors, exit program Count=0while count <3: name=input (' name>>: '). Strip () passwd=Input (' passwd>>: '). Strip () if name== ' AA ' and passwd== ' 123 ': print (' login successful ') else: print (' Input error,you have %d choice ' % (2-count)) count+=1# Upgrade requirements:## can support multiple user logins ( Prompt, save multiple account information through the list) # User 3 authentication failed, quit the program, restart the program when attempting to log on, or locked state (hint: you need to save the user locked state to the file) # # (Create a Db.txt file in this directory first) dic={ ' Egon1 ': {' password ': ' 123 ', ' Count ':0}, ' Egon2 ': {' password ': ' 123 ', ' Count ':0}, ' Egon3 ': {' password ': ' 123 ', ' Count ':0},}count=0while true: name=input (' name>>: '). Strip () if name not in dic: print (' User not present ') continue &Nbsp; with open (' Db.txt ', ' R ') as f: lock_ Users=f.read (). Split (' | ') if name in lock_users: print (' User%s is locked, '%name ') break if dic[name][' Count '] > 2: print (' too many, Lock ') with open (' Db.txt ', ' a ') as f: F.write ('%s| ' %name) break passwd=input (' passwd>>: ') if passwd==dic[name][' Password ']: print (' Landing success ') break else: print (' Username, password error ') dic [Name] [' Count ']+=1
Python Basic Exercise Exercises