Practice has proved that the long sitting injury demon. The most uncomfortable time of the weekend, the socks hand can not reach. In bed to raise a demon, read the "Pathon Concise Tutorial". Think of a question that had been answered by a colleague, "the knowledge of computers has been wasted for many years". But the interest in this area has not been erased.
Have learned a period of time in the past C + +, slightly through the fur, also did not write much code, the longest is not enough thousands of lines, and ultimately semi-finished products. Thinking back that year, that is still in the country as a teacher when the story. look at pathon, is because of the work of the reasons, want to know some data analysis knowledge (not to mention mathematics, it is sad to mention).
A piece of code written against the relevant syntax:
"""Address Book Management"""classaddress:p= {} personnum = 0 #Initializing Contacts def __init__(self): Self.personnum=0print (' existing%d contacts. ') %self.personnum) #find a contact for a named person defSearch (self,name):if(Nameinchself.p):return1Else: return0#Add a contact person defAddperson (self):Print('Enter your name:'), name=input ()Print('Enter your phone number:'), Tele=input () Self.p[name]=TeleSelf.personnum + = 1 Print('Add contacts successfully! '), #print (' Total contact%d '. '%self.personnum) #delete the specified contact. defDelperson (self,name):del(Self.p[name])#Show Contacts defDisp (self,name="'): ifName = ="': forNtinchSelf.p.items ():Print('%s\t%s'%(n,t))Else: Print('%s\t%s'%(Name,self.p[name]))#Save to file defSave (self): of= Open ('Addrs.txt','a') forNameinchSelf.p:of.write (Name+'\ t'+self.p[name]+'\ r') Of.close ()#Import from a text file defImport_from_file (self):Try: File= Open ('Addrs.txt','R') except: RaiseValueError ('File open failers.') whileTrue:aline=File.readline ()ifAline:aline=Aline.rstrip () T= Aline.rfind ('\ t') Self.p[aline[0:t]]= Aline[t+1:] Else: Breakfile.close ()defmenu ():Print('1. Open Contacts') Print('2. Create a new address book') Print('3. Add a contact') Print('4. Contact person Enquiry') Print('5. Delete a contact') Print('6. Save') Print('7. Exit') Print('Please select (1-7)') #defMain (): while1: Menu () cmd=input ()ifcmd >'7' orCMD <'1': Print('\nerror: Please enter the front menu corresponding to the serial number! \ n') ifcmd = ='6': Myadd.save ()ifcmd = ='1': Myadd=Address () myadd.import_from_file ()ifcmd = ='2': Myadd=Address ()Print('new contacts are already created \ n') Myadd.disp ()ifcmd = ='3': Myadd.addperson () myadd.disp ()ifcmd = ='4': Name= Input ('Enter the name you want to query:') if(Myadd.search (name) = = 1): Myadd.disp (name)Else: Print("not Found! \ n") ifcmd = ='5': Name= Input ('Enter the name you want to query:') if(Myadd.search (name) = = 1): Myadd.delperson (name)Else: Print('Please enter the correct contact person! \ n') Myadd.disp ()ifcmd = ='7': Exit ()if __name__=="__main__": Main ()
How to feel (compare C + +):
1. Do not worry about the data type, do not need to indicate the data type directly.
2. Don't worry ";" The number.
3. No familiar array char[], pointers, etc; no operators such as "| |", "&&".
4. Circular structure syntax is simple, the efficiency of writing code has improved.
5. The display function has changed.
Pathon Study (i)