ADVANCED DATASTRUCTURES

Jan 15th, 2014
Anonymous
Category:
Programming
Price: $20 USD

Question description

In this exercise the idea is to build a notebook which applies the Python data structure list as a note manipulation method when the program is executed, and saves the data in a bitwise mode with pickle. The program has the following features:
A) It is possible to add notes, with similar timestamps as earlier. 
B)It is possible to edit a note by selecting it from the list, and rewriting it with new data.
C) It is possible to delete notes separately based on the selection and 
D) Notebook loads an existing notebook file from the file "notebook.dat" if such a file exists.


When the program starts, the system should check for a notebook datafile "notebook.dat" and load it with pickle. If no such file exists, or there was a problem with the file, a new file is created and the user is notified "No default notebook was found, created one.". After this the basic main menu works as in the earlier notebook:


code:

import time  

import pickle 

mylist=[]

def check(z):

 try:

  s1 = open("notebook.dat","rb")

  contents=pickle.load(z)

  for i in contents:

   mylist.append(i)  

  s1.close()

  #s1.close()

 except IOError:

  print("No default notebook was found, created one.")

  s1 = open("notebook.dat","wb")

  s1.close()

   

a= True

nm="notebook.dat"

check(nm)

s1 = open(nm,"rb")

s1.close()

while a:

# print("Now using file ",nm)

 print("(1) Read the notebook\n(2) Add note\n(3) Edit a note \n(4) Delete a note \n(5) Save and quit")

 ch=int(input("Please select one: "))

 if ch==1:

  for i in mylist:

   print(i)

   

 elif ch==2:

   s2=input("Write a new note: ")

   s2+=":::"

   s2+=time.strftime("%X %x")

   mylist.append(s2)

   

 elif ch==3:

   print("The list has ",len(mylist)," notes.")

   chh=int(input("Which of them will be changed?: "))

   print(mylist[chh])

   s22=input("Give the new note: ")

   s22+=":::"

   s22+=time.strftime("%X %x")

   mylist[chh]=s22

 elif ch==4:

   

   print("The list has ",len(mylist)," notes.")

   chh=int(input("Which of them will be deleted?: "))

   print("Deleted note ",mylist[chh]) 

   mylist.pop(chh)

   

 elif ch==5:

  # print(mylist)

   a=False

   s1 = open("notebook.dat","wb")

   #mylist.append("\n")

   pickle.dump(mylist,s1)

   s1.close()

   print("Notebook shutting down, thank you.")

   

   





Tutor Answer

(Top Tutor) kukistars
School: Carnegie Mellon University

Studypool has helped 1,244,100 students

Review from student
Anonymous
" Thanks, good work "
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1819 tutors are online

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors