Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Tips to improve a simple"To-Do List" program?

Just started learning python, and got this idea during one of the early lessons. It is a simple to-do list program, where the user inputs a list of tasks coupled with the time they would like to complete the task. When the user is finished, the program prints out a list of the "tasks + 'at' + 'times".

I was wondering if anyone would like to look it over and offer any advice for how I might improve it!

to_do = list()
what_time = list()

input("Type DONE when you are finished scheduling your day.")

while True:
  task = input("What do you need to do today? ")
  if task == 'DONE':
    break
  else:
    time = input("What time do you need to do this? ")
  to_do.append(task)
  what_time.append(time)
  continue

print("Here is your to-do list:")

for (t,w) in zip(to_do, what_time):
  print(t + " at " + w)

Thanks! Zac

The one improvement I can think of is to have your code order the events by time before it prints it off. Since schedules are heavily dependent on them being order, I feel like this would be a great improvement. I'm not sure of the best way to do this, but here are my thoughts:

Make a new list for AM/PM. In your while loop, have it ask one last question after time which indicates whether we are talking AM or PM. You would then need to sort your list by first checking the earliest AM times, followed by the earliest PM times. Save these new lists.

Lastly, you can print these lists out just like you were while adding:

print(t + " at " + w + y) // y being AM/PM list

Just some thoughts.