At the end of the book 'A Byte of Python' I'm asked to do the following: Create your own command-line address-book program using which you can browse, add, modify, delete or search for your contacts such as friends, family and colleagues and their information such as email addresses and/or phone number. Details must be stored for later retrieval. Hint: Create a class to represent the person's information. Use a dictionary to store person objects with their name as the key. Use the pickle module to store the objects persistently on your hard disk. Use the dictionary built-in methods to add, delete and modify the persons. And here is the code I come up with after 10 minutes of thinking:
class Zhivko:
age = 20
occupation = 'student'
class Hristo:
age = 21
occupation = 'worker'
class Margata:
age = 21
occupation = 'local fool'
dictionary = {'zhivko' : 'student',
'hristo' : 'worker',
'margata': 'local fool'
}
print Zhivko.age
print('Zhivko is a ',dictionary['zhivko'])
I just want to know if I'm on the right way of solving that? And also do I have to make the program in such a way that when ran in Command Prompt the user can browse, add, delete and modify the dictionary by for example typing a command 'add' for adding and then typing the name and the occupation of the person, and the python script has to be written in such a way that after the user does that it automatically goes into the dictionary?


Sign In
Create Account


Back to top









