Question: This is python I am trying to finish up a programming assignment where I need the code to output this General List: ------------- [3] Pick
This is python
I am trying to finish up a programming assignment where I need the code to output this
General List: ------------- [3] Pick up flowers (02/13/2022) [1] Clean garage [3] Start working on final project (02/14/2022) Bindge 'The Office' Season 1 (03/07/2022) Grocery Store List: ------------------- Milk Eggs Bread Waffles Bananas Books List: ----------- [2] Drop off library books (02/15/2022) [3] Books Galore Annual Clearance (03/01/2022) [2] Pick next book club selection
but instead I get this
General List: ------------- Pick up flowers (02/13/2022)[3] Clean garage[1] Start working on final project (02/14/2022)[3] Bindge 'The Office' Season 1 (03/07/2022) Pick up flowers (02/13/2022)[3] Start working on final project (02/14/2022)[3] Bindge 'The Office' Season 1 (03/07/2022)
Grocery Store List: ------------------- Milk Eggs Bread Waffles Bananas
Books List: ----------- Drop off library books (02/15/2022)[2] Books Galore Annual Clearance (03/01/2022)[3] Pick next book club selection[2] Drop off library books (02/15/2022)[2] Books Galore Annual Clearance (03/01/2022)[3] with this error message
Traceback (most recent call last):
main()
agenda.load( file_name )
if reminder_list is not None: UnboundLocalError: local variable 'reminder_list' referenced before assignment
This uses 2 files we have the Reminder.pv that has code that will be imported to another file
class Task: def __init__(self, title, priority): self.title = title self.priority = priority
def get_title(self): return self.title
def get_priority(self): return self.priority
def __repr__(self): return ",".join([self.title, str(self.priority)])
def __str__(self): return "{}{}".format( self.title, "" if self.priority == 0 else f"[{self.priority}]" )
class Reminder(Task): def __init__(self, title, priority, due_date): super().__init__(title, priority) self.due_date = due_date
def get_due_date(self): return self.due_date
def __repr__(self): return ",".join([self.title, str(self.priority), str(self.due_date)])
def __str__(self): if self.due_date is None: return "{}{}".format( self.title, "" if self.priority == 0 else f"[{self.priority}]" ) else: return "{} ({}){}".format( self.title, self.due_date, "" if self.priority == 0 else f"[{self.priority}]" )
class ReminderList: def __init__(self, list_name): self.list_name = list_name self.tasks = []
def get_list_name(self): return self.list_name
def add_task(self, title, priority): self.tasks.append(Task(title, priority))
def add_reminder(self, title, priority, due_date): self.tasks.append(Reminder(title, priority, due_date))
def remove_task(self, task): self.tasks.remove(task)
def remove_reminder(self, reminder): self.tasks.remove(reminder)
def get_tasks(self): return [t for t in self.tasks if isinstance(t, Task)]
def get_reminders(self): return [r for r in self.tasks if isinstance(r, Reminder)]
class Agenda: PRIORITY_NONE = 0 PRIORITY_LOW = 1 PRIORITY_MEDIUM = 2 PRIORITY_HIGH = 3
def __init__(self): self.reminder_lists = []
def add_list(self, title): new_list = ReminderList(title) self.reminder_lists.append(new_list) return new_list
def print_list(self, title): reminder_list = self.get_reminder_list(title) if reminder_list is None: print(f"Could not find list {title}") return
print(f"{title} List:") print("-" * (len(title) + 6))
for item in reminder_list.get_tasks() + reminder_list.get_reminders(): print(item)
def get_reminder_list(self, title): for reminder_list in self.reminder_lists: if reminder_list.get_list_name() == title: return reminder_list return None
def load(self, filename): with open(filename, 'r') as agenda_data: for agenda_item in agenda_data: if agenda_item[0] == 'L': fields = agenda_item[1:].split(',') self.add_list(fields[0])
if agenda_item[0] == 'R': fields = agenda_item[1:].split(',') reminder_list = self.get_reminder_list(fields[0]) if reminder_list is not None: reminder_list.add_reminder(fields[1], int(fields[2]), fields[3].strip())
def save(self, filename): with open(filename, 'w') as agenda_data: for reminder_list in self.reminder_lists: agenda_data.write(f"L{reminder_list.get_list_name()} ") for reminder in reminder_list.get_reminders(): agenda_data.write(f"R{reminder.get_title()},{reminder.get_priority()},{reminder.get_due_date()} ")
and this is the Reminder application that the code gets imported to called ReminderApp.pv
from Reminder import *
def main_setup(file_name, agenda): general_list = agenda.add_list("General") grocery_list = agenda.add_list("Grocery Store") books_list = agenda.add_list("Books") general_list.add_reminder("Pick up flowers", agenda.PRIORITY_HIGH, "02/13/2022") general_list.add_task("Clean garage", agenda.PRIORITY_LOW) general_list.add_reminder("Start working on final project", agenda.PRIORITY_HIGH, "02/14/2022") general_list.add_reminder("Bindge 'The Office' Season 1", agenda.PRIORITY_NONE, "03/07/2022") grocery_list.add_task("Milk", agenda.PRIORITY_NONE) grocery_list.add_task("Eggs", agenda.PRIORITY_NONE) grocery_list.add_task("Bread", agenda.PRIORITY_NONE) grocery_list.add_task("Waffles", agenda.PRIORITY_NONE) grocery_list.add_task("Bananas", agenda.PRIORITY_NONE) books_list.add_reminder("Drop off library books", agenda.PRIORITY_MEDIUM, "02/15/2022") books_list.add_reminder("Books Galore Annual Clearance", agenda.PRIORITY_HIGH, "03/01/2022") books_list.add_task("Pick next book club selection", agenda.PRIORITY_MEDIUM)
def main(): agenda = Agenda() file_name = "myagenda.dat" main_setup( file_name, agenda ) agenda.print_list("General") print() agenda.print_list("Grocery Store") print() agenda.print_list("Books")
agenda.load( file_name ) main()
Hopefully this is the only error I am getting and it will work as it is intended. Please let me know what the error is and how to fix it to output the code on the top.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
