i am trying to write a program that if a user press 1, it reads the file, if 2, it write to the file and if 3, it erase the file. Unfortunately, the code stop working after the first input from user. Is it possible to write a function for that?
while True:
print("(1) Read the notebook")
print("(2) Add note")
print("(3) Empty the notebook")
print("(4) Quit")
user_input = input("Please select one: ")
if user_input == 1:
readfile = open("notebook.txt","r")
content = readfile.read()
print(content)
readfile.close()
elif user_input == 2:
new_input = input("Write a new note: ")
readfile = open("notebook.txt", "a")
readfile.write(new_input)
readfile.close()
elif user_input == 3:
readfile = open("notebook.txt", "w")
readfile.close()
elif user_input == 4:
break
print("Notebook shutting down, thank you.")