Skip to content
  • Categories
  • Recent
  • Groups
  • Users
  • Tags
  • Popular
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Lumen)
  • No Skin
Collapse
Brand Logo
LinksL

Links

@Links
Clown 🤡 Pythons the goat Nintendo Switch Users Eeveelution Fan! Brazilian pepsi lovers meggy lovers NOCTURNAL Smash Ultimate straight allies!
About
Posts
71
Topics
5
Shares
0
Groups
12
Followers
11
Following
11

Posts

Recent Best Controversial

  • Act along the thing
    LinksL Links

    DROP ON UR KNEES AND BARK LIKE U WANT IT (lol)

    Edge Of The Forum

  • !~Joke of the day~!
    LinksL Links

    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!

    Edge Of The Forum

  • "retroslop" (huge rant)
    LinksL Links

    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

    Regular Blogs

  • name for social network site
    LinksL Links

    @danniltrifonov we do that

    Web Development

  • can someone give me some tips on how to make Python programs that write data to external files?
    LinksL Links

    Hope it worked :)

    Web Development

  • can someone give me some tips on how to make Python programs that write data to external files?
    LinksL Links

    1. Wrong logic in is_minor()

    You wrote:

    if age > 18:
        is_minor = True
    else:
        is_minor = False
    

    This means someone over 18 is considered a minor, which is backwards.
    It should be:

    if age < 18:
        is_minor = True
    else:
        is_minor = False
    

    Or even shorter:

    return age < 18
    

    2. Missing parenthesis in file.write()

    In write_to_file():

    file.write(name + ", "
    

    You forgot the closing ) for that file.write call.


    3. Writing a boolean directly to a file

    file.write() needs a string.
    You’re trying to write:

    file.write(minor)
    

    But minor is a boolean (True or False). 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()
    
    Web Development

  • Best music genre?
    LinksL Links

    Tbr I really like punk rock but idk about y'all. (example: Basket case by Green Day)

    Trivia
  • 1 / 1
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Groups
  • Users
  • Tags
  • Popular