samedi 31 mars 2018

Ending input() by "if ... is not None" using Python3.6

I'm very new to Python. I'm trying to make a todo-list (a txt file) that I can then add stuff to. I'm struggling with the correct method of making the script stop when I'm done entering things.

I've tried different ways of making while loops and if statements, but the script always either just stops or goes on forever.

I think the problem might lie with me assigning "not None" to a changing variable, but I'm not sure. This is my code:

import time
from datetime import date

todo_file = open(f"ToDos_{date.today()}", 'a')

todo_file.write(input("What do you need to do tomorrow? "))
todo_file.write("\n")

todo = input("What else? ")

if todo is not None:
    todo_file.write(todo)
    todo_file.write("\n")
else:
    pass

todo_file.close()

Any other criticisms to how I wrote this are also very welcome.

Aucun commentaire:

Enregistrer un commentaire