log_action(path, user, action) that appends a line formatted as user|action to the file, creating it if it doesn't exist. Explain-by-code why mode 'a' and not 'w'.log_action('audit.txt', 'rahul', 'login')file gains the line 'rahul|login'
Mode 'a' preserves existing lines and adds to the end.
'a' creates the file when missing, appends when present.
An f-string builds the line.