Question: Need help with a python assignment Here is the task.py I currently have: class Task: Shows the format for each file Attributes:

Need help with a python assignment
Here is the task.py I currently have:
class Task:
"""Shows the format for each file
Attributes:
desc (str): description of the task
date (str): due date of the task (formatted in MM/DD/YYYY)
time (str): time the task is due (formatted in HH:MM)
"""
def __init__(self, desc, date, time):
self.description = desc
self.date = date
self.time = time
def get_description(self):
return self.description
def __str__(self):
return f"{self.description}- Due: {self.date} at {self.time}"
def __repr__(self):
return f"{self.description},{self.date},{self.time}"
def __lt__(self, other):
self_date_time = f"{self.date}{self.time}"
other_date_time = f"{other.date}{other.time}"
return self_date_time other_date_time
Here is the main.py:
from task import Task
def main_menu():
print("1. Display current task")
print("2. Mark current task complete")
print("3. Postpone current task")
print("4. Add new task")
print("5. Save and quit")
choice = int(input("Enter choice: "))
return choice
def read_file():
"""Reads the designated file and adds them to a list"""
tasks =[]
try:
with open("tasklist.txt",'r') as file:
for line in file:
desc, date, time = line.strip().split(",")
task = Task(desc, date, time)
tasks.append(task)
#Exception made just in case no file is found.
except FileNotFoundError:
pass
return sorted(tasks)
def write_file(tasklist):
"""Writes to the tasklist.txt file"""
with open("tasklist.txt",'w') as file:
for task in tasklist:
file.write(repr(task)+'
')
def get_date():
"""Retrieves the month, day and year when asked"""
while True:
try:
month = input("Enter month: ").zfill(2)
day = input("Enter day: ").zfill(2)
year = input("Enter year: ")
month, day, year = int(month), int(day), int(year)
if 1= month =12 and 1= day =31 and 2000= year =2100:
return f"{month:02}/{day:02}/{year}"
else:
print("Invalide date. Please enter a valid date.")
except ValueError:
print("Invalid input. Please enter numbers only.")
def get_time():
"""Retrieves the time in military hours"""
while True:
try:
hour = input("Enter hour: ").zfill(2)
minute = input("Enter minute: ").zfill(2)
#Conditions for Time
hour, minute = int(hour), int(minute)
if 0= hour =23 and 0= minute =59:
return f"{hour:02}:{minute:02}"
else:
print("Invalid time. Please enter a valid time.")
#If the user inputs an str
except ValueError:
print("Invalid input. please enter numbers only.")
def main():
"""Defines a list"""
tasklist = read_file()
while True:
print("
-Tasklist-")
print("You have", len(tasklist), "tasks.")
#Shows the menu & asks for the input from one of 5 choices
choice = main_menu()
#Shows the current task on the list.
if choice ==1:
if tasklist:
print("Current task is: ")
print(tasklist[0])
else:
print("All tasks finished.")
#Marks the current task for completion & removes it from the list.
elif choice ==2:
if tasklist:
print("Marking current task as complete:")
print(tasklist.pop(0))
else:
print("All tasks finished.")
#Postpones the task and asks for a new date and time for the task.
elif choice ==3:
if tasklist:
print("Postponing task:")
print(tasklist[0])
new_date = get_date()
new_time = get_time()
task = tasklist.pop(0)
new_task = Task(task.description, new_date, new_time)
tasklist.append(new_task)
tasklist.sort()
else:
print("All tasks finished.")
#Creates a new task.
elif choice ==4:
desc = input("Enter a task: ")
date = get_date()
time = get_time()
new_task = Task(desc, date, time)
tasklist.append(new_task)
tasklist.sort()
#Saves the items of the list to the tasklist.txt file even if empty.
elif choice ==5:
write_file(tasklist)
print("Saving and exiting.")
break
#When the choice input is not a value stated from 1 to 5.
else:
print("Invalid choice. Please choose a number listed.")
if __name__=="__main__":
main()
Need help with a python assignment Here is the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!