DROP ON UR KNEES AND BARK LIKE U WANT IT (lol)
Posts
-
Act along the thing -
!~Joke of the day~!sometimes you need help from great master toriel.
knock knock
Who is there?
Old lady!
Old lady who?
Oh! i didn't know you could yodel!
-
"retroslop" (huge rant)Like RIGHHT??? I hate how they call bacon guy ugly while they get those stupid ahh faces w/ scars and hair that looks like dried kelpt
-
name for social network site@danniltrifonov we do that
-
can someone give me some tips on how to make Python programs that write data to external files?Hope it worked :)
-
can someone give me some tips on how to make Python programs that write data to external files?1. Wrong logic in
is_minor()You wrote:
if age > 18: is_minor = True else: is_minor = FalseThis means someone over 18 is considered a minor, which is backwards.
It should be:if age < 18: is_minor = True else: is_minor = FalseOr even shorter:
return age < 18
2. Missing parenthesis in
file.write()In
write_to_file():file.write(name + ", "You forgot the closing
)for thatfile.writecall.
3. Writing a boolean directly to a file
file.write()needs a string.
You’re trying to write:file.write(minor)But
minoris a boolean (TrueorFalse). You must convert it to string:file.write(str(minor))
4. You’re opening the file with
r+r+means read/write without truncating. If the file doesn’t exist, it will throw an error. If you just want to append, use"a"or"a+". If you want to overwrite, use"w".
Fixed Code
Here’s a working version:
# Open in append mode file = open("database.txt", "a") name = input("Enter your name: ") age = int(input("Enter your age: ")) def is_minor(age): return age < 18 minor = is_minor(age) def write_to_file(name, age, file, minor): file.write(name + ", ") file.write(str(age) + ", ") file.write(str(minor) + "\n") write_to_file(name, age, file, minor) file.close() -
Best music genre?Tbr I really like punk rock but idk about y'all. (example: Basket case by Green Day)