A running program's variables are like writing on a whiteboard: quick, handy, and wiped when the session ends. A file is the notebook you copy the important results into before you leave. In Python, f = open('scores.txt', 'a') opens the notebook at the first blank line, f.write('Ana,95\n') adds a line (the \n marks the line break), and f.close() puts the notebook back on the shelf. Next week, open('scores.txt', 'r') and f.read() bring the same text back into memory.
Three details decide whether the data survives. The mode: 'w' empties the file the moment it opens, before you write anything, which suits a fresh save but destroys a log; 'a' keeps everything and adds to the end; 'r' fails with FileNotFoundError if the file is missing. Closing: writes are often held in a memory buffer and reach the disk only when the buffer fills or the file is closed, so a crash before close() can lose the last writes; with open(...) as f: closes automatically, even after an error. Text: a text file stores characters, so the score 95 is written as '95' and must be converted back with int() after reading.
Reading a file is a kind of input, but not every input is a file. input() waits for a person at the keyboard, and the answer is gone when the program ends; a file is already on disk and will still be there tomorrow. Choose a file when the data must outlast the run or be shared, and keyboard input when a person is answering in the moment.
Think of it like this. Files are a program's notebook, and the open mode is how you approach it: 'r' is reading without a pen, 'a' is turning to the first blank page, and 'w' is tearing out every page before you start. Closing is shutting the notebook so nothing is left half-written. Unlike torn paper, an emptied file cannot be fished out of the bin.
Core idea. Files provide persistent storage. Without files, all data would be lost when the program ends. Open, read/write, close is the standard pattern.