Abc

adsgsdfgsdfgdfgsdfgdfgcdfdfgdfgcg

https://docs.python.org/3/tutorial/inputoutput.html
in Block 7.2

I don't know exactly what you trying to find, but i think you looking for a for line in file and then check every line for the variable.

2 Likes

You got a couple problems here. Mode "a" will position the File Handle at the end of the file.

You need to do something like this

with open("number.txt", "r") as fh:
    for line in fh:
        if number == line.rstrip():
            "do stuff if the number is in the file"
            sys.exit()
with open("number.txt", "a") as fh:
    "write number"

Could have done it all for you, but there's a few more gotcha's you're gonna hit with this program that you want to understand. The return character will be part of the "line" returned by the for loop. And you can't read a file with the a flag. The "with" statement also automatically closes the file handle for you when you exit the indent block without having to call close.

1 Like

Windows, MacOs, Linux?

Im at work, so give me a minute.

Good work. I'll post a variant of this code here for educational purposes.