python程序设计简明教程课后答案_Python简明教程最后的练
习题
作为⼀个菜鸟, 没点进步都是值得记录的. 嘿嘿, 今天重新看了⼀遍Python简明教程, 终于独⽴完成了最后的练习(⽼鸟勿笑). 特粘贴代码在下⾯,希望⼤家指导.b站随机数生成器
import cPickle class Person:    '''Represents a person,which includes name, phone, email and so on.'''    phonebook = {}            #Create a dict for storing the contact    def __init__(self):        self.name = ''        self.phone = ''        ail = ''            def add(self):        '''Add a contact.'''        self.name = raw_input('Please input a name: ')        if
Person.phonebook.has_key(self.name):            print 'The name is exist!'        else:            self.phone = raw_input('Please input the phone: ')            ail = raw_input('Please input the email: ')            Person.phonebook[self.name] =
self.phone + ' ; ' + ail            try:                cPickle.dump(Person.phonebook, file('', 'w'))                print 'Contact saved.'            except IOError as ioerr:                print 'File error:(add)' + str(ioerr)                              def
modify(self):        '''Modify a contact's information.'''        self.name = raw_input('Please input the name you want to modify: ')        if Person.phonebook.has_key(self.name):            self.phone = raw_input('Please input the phone: ')            ail = raw_input('Please input the email: ')            try:                cPickle.dump(Person.phonebook, file('', 'w'))                print 'Contact saved.'            except IOError as ioerr:                print 'File error:(modify)' + str(ioerr)        else:
print 'There\'s no one named %s,please confirm your input.' %self.name              def delete(self):        '''Delete a contact's information.'''        self.name = raw_input('Please input the name you want to delete: ')        if
汇编和汇总的意思一样吗Person.phonebook.has_key(self.name):            del Person.phonebook[self.name]            try:
cPickle.dump(Person.phonebook, file('', 'w'))                print 'Contact saved.'            except IOError as ioerr:                print 'File error:(delete)' + str(ioerr)        else:            print 'There\'s no one named %s,please confirm your input.'
%self.name                          def search(self):        '''Search and show a contact's information.'''        Person.phonebook = cPickle.load(file(''))        self.name = raw_input('Please input the name you want to search: ')        if
php程序设计基础教程耿倩
Person.phonebook.has_key(self.name):            print            print 'Name: %s' %self.name            print 'Phoen&Email: %s'
python编程基础教程课后答案>黑马学php吗
%Person.phonebook[self.name]            print        else:            print 'There\'s no one named %s,please confirm your input.' %self.name    def view(self):        '''Show all contacts's information.'''        try:            Person.phonebook =
cPickle.load(file(''))        except IOError as ioerr:            print 'File error:(view)' + str(ioerr)        for
c语言二维数组的输入self.name,self.phone in Person.phonebook.items():            print              print 'Name: %s,\nPhone&Email: %s' %(self.name, self.phone)            print  if __name__ == '__main__':    p = Person()    print '''Hello,I'm you phonebook guide,you can input "add" to add a person's              information,"modify" to modify a contact, "delete" to delete a contact, "search" to search person's              information, "quit" to quit and exit system,"view" to show all contacts information'''    while True:        inputChar = raw_input('What are you going to do(add/modify/search/delete/view/quit)? \n>>')              if inputChar == 'add':            p.add()        elif inputChar == 'modify':            p.modify()        elif inputChar == 'delete':            p.delete()        elif inputChar == 'search':            p.search()        elif input
Char == 'view':            p.view()        elif inputChar == 'quit':            print 'Exit the system.'            break        else:            print 'You\'ve input a wrong command character,Please input a command again.(The command is one of [add/modify/search/delete/view/quit)]'

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。