osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

No subject


On 1/4/20 3:29 PM, William Johnsson wrote:
> Hello! My name is William and im 14 years old and live in sweden.  Im
> pretty new to programing in python and i need some help with code,
> (That?s why i?m here). But i couldn?t really find what i was
> searching for on the internet. I?m trying to write code that can
> check only the first line in a .txt file and check if it?s the same
> as the int 1000.   I preferably want it to be an if satement but
> anything works, i just don?t know how i should write it. I?ve been
> browsing the internet for a solution but sadly can?t seem to find a
> solution to it.
> 
> I don?t really know if this is the right way to get help or even if
> this email is for something else. Hopefully i will get some kind of
> response.
> 
> Best regards, William

Welcome, William.  Another mailing list you might want to post to is the
Python Tutor list (https://mail.python.org/mailman/listinfo/tutor) which
is focused on people learning Python.

Seems like your problem can be broken down into a few steps:
1. Open a file
2. Read the first line
3. look for "1000" in that line.

Learning how to read from a text file would probably be the first thing
to look into.  See in particular chapter 7.2 in this section of official
tutorial.  https://docs.python.org/3/tutorial/inputoutput.html

You may also google for other examples of opening and reading lines from
a text file in Python.

Once you've been able to read in a line, you can do a simple search in
that line using the "in" keyword (mentioned part way down the page
https://docs.python.org/3/library/stdtypes.html in the section called
"Common Sequence Operations").

Hopefully you'll find this useful rather than just giving you a complete
little program (where's the fun in that!).