so lately i've been learning about making Python programs that write to text files. and I made an example of such (in this we assume in the directory theres a file called "database.txt")
file = open("database.txt","r+")
name = input("Enter your name: ")
age = int(input("Enter your age: "))
def is_minor(age):
is_minor = False
if age > 18:
is_minor = True
else:
is_minor = False
return is_minor
minor = is_minor(age)
def write_to_file(name, age, file, minor):
file.write(name + ", "
file.write(str(age) + ", ")
file.write(minor)
write_to_file(name, age, file, minor)
file.close()
and now my problem with this is: it does actually work, it writes allow 4 values to the txt file, but everytime it runs it gets rid of what was there before. I don't know if that means that i'm using the wrong file.open("database.txt,"r+"). maybe the "r+" isn't for appending. honestly the problem is likely the file.write statement, so if anyone knows what file.write() statement i could use to append information to the file without overriding the contents, that would be amazing.

