Recently learned some of the basic data structure of python, here through a small program to do a small summary, their own comparative preference dictionary, the program mainly uses the dictionary data structure.
1. through the user name and password authentication to log on to the system, registration needs to login.
2. after the certification, the system will give a few travel plans, the plan has a choice of destinations and travel days.
3. after the purchase is complete, settle the total consumption amount and exit.
The Python knowledge points that are expected to be used are:
1. methods for manipulating and listing of general-purpose sequences.
2. the method of the dictionary.
3. Process Control.
import time#create authentification list authlist={' zhang01 ': ' 1234qwer ', ' lee10 ': ' 1qaz ', ' Wang33 ': ' 567890 '}user=raw_input (' please enter your username: ') passwd=raw_input (' please enter your password: ') #for key,value in authlist.items (): # if user== key and passwd==value:# print ' login successful! ' # elif user!=key: # print ' no such account! ' # elif passwd!=value:# print ' invalid passwd! ' # break#login verification# attempted to iterate through the dictionary method with a loop, but did not succeed. while true: if user in authlist: if passwd==authlisT.get (user): print ' login successful! ' break else: print ' invalid password! ' passwd=raw_input (' Please enter your password: ') continue else: print ' no such account,please register! ' newuser= raw_input (' please enter a username: ') if newuser not in authlist: print ' username is ok! ' newpasswd=raw_input (' please enter a password: ') Authlist.setdefault (NEWUSER,NEWPASSWD) print ' register successful! ' break else: print ' username is already existed! ' #travel plans offerc1={' 1 ': +, ' 3 ': +, ' 5 ': $, ' + ': 1000}c2={' 1 ': 300, ' 3 ' : +, ' 5 ': 1300}c3={' 1 ': +, ' 3 ': +, ' 5 ':, ' + ': 1500}c4={' 1 ': +, ' 3 ':, ' 5 ': +, ' + ': 1700}costs=dict (DOMESTIC=C1, JAPAN=C2,EUROPE=C3,USA=C4) print ' the costs for different destinations for 1,3,5,14 days: \n ', costsprint ' \ n ' time.sleep (3) shlist={}index= 0a=1cost=0d=0while a: dest=raw_input (' Please choose your destionation: ') days=raw_input (' please choose your days of staying: ') cost=costs[dest][days] print ' you want to spend %s days in %s,and the cost is $%s '% (Days,dest,cost)  &Nbsp; shlist[index]= (dest,days,cost) index +=1 d +=cost con=raw_input (' Are you done shopping? yes (Y) or no (N): ') if con== ' Y ':a=0 else:a=1print ' Your shopping cart has %d item:%s, total cost is $%d ' % (Index,shlist.values (), D) key=raw_input ( ' do you want to check out (C) or delete some item in shopping list (D)? ') if key == ' C ': print ' your current shopping list is: ' print shlist print ' please pay $%d ' %dif key == ' d ': Print shlist k=raw_input ( ' Please enter the item number you want to delete in your shopping list: ') shlist.pop (int (k)) if shlist=={}: print ' Your current shopping list is empty ' else: print ' Your current shopping list is: ' print shlist
Autenlist and Travelplans can be stored separately in TXT files, opened with open, ReadLines read.
Returns the position of an element in the list by index, which then accesses the value of that position in its corresponding list.
You can add a budget and balance function.
Python Learning notes-cottage Ctrip (list, string, dictionary and Process Control summary)