Python little Exercise 1 movie manager

Source: Internet
Author: User

Basic functions to complete: Add business Card Delete business card Modify business Card Query business card exit system

Idea: Use a dictionary as a business card to store personal information, and then put the business card into the list.

Cardlist = []#list, which holds everyone's business cards, each of which is a dictionary. defMenu ():#used to prompt for user function options    Print('======== Card Manager ========')    Print('1 Add business Card 2 Delete business Card 3 Modify business Card 4 Query Business Card 5 Show all 6 exit system')defAddcard ():#Add a business card functionCard = {}#local variables, this dictionary is used to temporarily save the business card to be addedcard['name'] = input ('Please enter the name of the person to add:')#assigns the name to the dictionary card's ' name ' key corresponding to the valuecard['Telephone'] = input ('Please enter the add person phone:')#Ibid .Cardlist.append (Card)#Add a new business card to the list    Print(card)#Print this business card    Print('has been added')defDeletecard (): Deletename= Input ('Please enter the name of the business card you want to delete:')     forTempinchCardlist:#list traversal, note that temp is a dictionary (a business card)        iftemp['name'] = = Deletename:#temp[' name ' is value and determines whether the person to be deleted is a list ofCardlist.remove (temp)#Delete the temp element of the list (a business card)            Print('has been removed')defModifycard (): Tomodifyname= Input ('Please enter the name of the business card you want to modify:') Newtemp={}#used to save the modified business card     forTempinchcardlist:iftemp['name'] = = Tomodifyname:#Select the temp that matches the name you want to delete, and then work with this tempNewtemp =Temp NewName= Input ('Please enter a new name:') newtemp['name'] =newName Newphone= Input ('Please enter a new phone:') newtemp['Telephone'] =newphone cardlist.remove (temp)#DeleteCardlist.append (newtemp)#Add            Print('has been modified')defFindcard (): Findflag= 0#whether to find the flag bitFindName = input ('Please enter the name you want to find:')     forTempinchcardlist:iftemp['name'] = = FindName:#Select the temp that matches the name you want to find, and equality means find            Print(temp)#Print the business card you're looking forFindflag = 1#flag position 1, indicates found    ifFindflag = =0:Print('didn't find')defShowallcard ():Print(cardlist)#Print List, i.e. all business cardsdefMain (): whileTrue:menu () Choice= Int (Input ('Please enter the selection function number:'))        ifChoice = = 1: Addcard ()#Add a business card            Continue        elifChoice = = 2: Deletecard ()#Delete a business card            Continue        elifChoice = = 3: Modifycard ()#Modify a business card            Continue        elifChoice = = 4: Findcard ()#Find a business card            Continue        elifChoice = = 5: Showallcard ()#Show All        elifChoice = = 6:            Print('has exited! ')             Break   #ExitMain ()#calling the main function

Python little Exercise 1 movie manager

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.