Python3 study notes-dictionaries and list exercises

Source: Internet
Author: User

First, the Dictionary practice _ registration Check

Requirement Point Description:

1. Use a dictionary to store existing user names, passwords

2, determine the input user name, password, confirm password can not be empty: strip ()

3. User name cannot be duplicated: key in Dirc

4, two times password should be input consistent

5, error 3 prompt error Too many times: for, Else

user = {    'Fengfeng':'123456',    'Fangfang':'456788'} forIinchRange (3): Username= Input ('Please enter user name'). Strip () passwd= Input ('Please enter your password'). Strip () cpasswd= Input ('Please enter your password again'). Strip ()ifUsernameinchUser#the dictionary uses in to judge the word, just to determine whether the key exists        Print('user name has been registered')    elifpasswd! =cpasswd:Print('two times the input password is inconsistent')    elifUsername = ="'orpasswd = ="' orCPASSWD = ="':        Print('the user name or password cannot be empty')    Else:        Print('Congratulations, the registration is successful!') User[username]=passwd#the dictionary inserts new data         BreakElse:    Print('excessive number of errors')Print(user)

Second, list practice

1. Verifying the user name is legal

Requirement Point Description:

1. Enter your account #input

2, if the account exists, the hint has been registered, if not exist, let him register #列表比对all_users [],count ()

3. Cannot be empty #strip ()

4. Length of user name length 6-12 len ()

5. Enter up to 3 times #循环

All_users = ['Fengfeng','Fangfang','Xiaofeng'] forIinchRange (3): User= Input ('Please enter user name:'). Strip ()ifLen (user) >5 andLen (user) <13:        ifAll_users.count (user) >0:Print('user name has been registered')        Else:            Print('user name is available, register it quickly')             Break    Else:        Print('user name length needs to be between 6-12 bits')Else:    Print('excessive number of failures')

1, two-dimensional list value

Requirement Point Description: Group the students who have handed in and do not hand in the job, and print

stus=[      ['Xiao Ming','Not delivered'],['Xiao Qing','has been handed'],      ['Small white','has been handed'], ['Little Violet','has been handed'],      ['Little Red','Not delivered'], ['Little Green','Not delivered'],      ['Xiao Huang','Not delivered'], ['Little Black','has been handed']]pass_list=[]#all the students who have handed in their homeworkFail_list=[]#students who do not hand in their homework forStuinchStus:status= Stu[1] Name=Stu[0]ifStatus = ='Not delivered': Fail_list.append (name)Else: Pass_list.append (name)Print('The student who has handed in the job is:%s, total%s personal'%(Pass_list,len (pass_list)))Print('non-handed jobs:%s, total%s personal'% (Fail_list,len (fail_list)))

Python3 study notes-dictionaries and list exercises

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.