Ok so I've wrote a code and used if statement and if statement is not doing what its supposed to do its just keep executing the fist case even if i type anything elsenything else.
while True:
user_input = input("Type add, show, edit, completed or exit: ")
user_input: str = user_input.strip()
if 'add' or 'Add' in user_input:
todo = user_input[4:] + '\n'
with open('files/todos.txt', 'r') as file:
todos = file.readlines()
todos.append(todo)
with open('files/todos.txt', 'w') as file:
file.writelines(todos)
elif 'show' or 'Show' in user_input:
with open('files/todos.txt', 'r') as file:
todos = file.readlines()
# todos_without_breakline = [item.strip('\n') for item in todos]
for index, item in enumerate(todos):
item = item.strip('\n')
print(f"{index+1}.{item}")
elif 'edit' or 'Edit' in user_input:
numbere = int(input("Enter the number of todo to edit: "))
new_todo = input("Enter the new todo: ")
with open('files/todos.txt', 'r') as file:
todos = file.readlines()
todos[numbere - 1] = new_todo + "\n"
with open('files/todos.txt', 'w') as file:
file.writelines(todos)
elif 'completed' or 'Completed' in user_input:
numberc = int(input("Enter the number of todo that is completed: "))
with open('files/todos.txt', 'r') as file:
todos = file.readlines()
index = numberc - 1
todo_to_remove = todos[index].strip('\n')
todos.pop(index)
with open('files/todos.txt', 'w') as file:
file.writelines(todos)
message = f"Todo '{todo_to_remove}' is removed from the list"
print(message)
elif 'exit' or 'Exit' in user_input:
break
else:
print("Unknown Command")
print("Bye")
Heres the thing when i get prompted i try to add todos by typing "add Pay chess". Ok thats done but now if i type "show" i still don't get anything where i should have printed the whole todo file. and heres another thing if you type "show Play chess" IT WILL ADD "PLAY CHESS: TO THE TODO LIST. means no matter what i type it just keeps executing the fist AKA add case. I dont know what to do so to be very honest i havent tried anything accept removing "or" in cases and converting it into if only statement.
Plaese help.
5P33DC0R3