3.12 & 3.13 Hacks
Procedure to help with my assignments
class Assignment:
def __init__(self, name, due_date):
self.name = name
self.due_date = due_date
# create a list to store all the assignments
assignments = []
# prompt the user to input their assignments and due dates
while True:
# ask the user if they want to add an assignment
add_assignment = input("Do you want to add an assignment? (yes/no) ")
if add_assignment.lower() == "yes":
# if yes, ask for the assignment name and due date
name = input("Enter the assignment name: ")
due_date = input("Enter the due date (MM/DD/YYYY): ")
# create an assignment object and add it to the list
assignment = Assignment(name, due_date)
assignments.append(assignment)
else:
# if no, break out of the loop
break
# print out the assignments and their due dates
print("Here are your assignments:")
for assignment in assignments:
print(f"{assignment.name} - Due on {assignment.due_date}")
- This code defines a class called
Assignment
, which represents a single assignment with a name and due date. The class has an__init__
method that initializes each instance of the class with a name and due date. - The code then creates an empty list called
assignments
to store all of the assignments that the user will enter. - It then enters a loop that will continue until the user indicates that they don't want to add any more assignments. Inside the loop, the code prompts the user to add an assignment and asks for the assignment name and due date.
- When the user enters this information, the code creates a new
Assignment
object and adds it to the list of assignments. - After the user indicates that they don't want to add any more assignments, the code prints out a list of all the assignments and their due dates.