I have a great idea for a homework note pad and I wrote the basics of the program. The problem is that when I add more (I rerun the program) all the contents get wiped out and replaced with the new homework assignment. Is there any way I can fix this?
def query_period(agenda_file):
per = input("What period is it?")
if per in ["1", "2", "3", "4", "5", "6", "7", "8"]:
input_and_write_homework(agenda_file)
else:
print("Invalid choice")
def input_and_write_homework(file):
hw = raw_input("What is the homework?")
file.write(hw)
if __name__ == "__main__":
agenda = open("agenda.txt", "w+")
query_period(agenda)
agenda.close()
To append to a file in python use the ‘a’ attribute, so change:
to:
You should probably be using raw_input() and type cast to a string, instead of input().