I need help with this exercise! Please

def count(f_in, f_out):
    f = open(f_in, "r")
    m = open(f_out, "w")
    for line in f:
        o = line.find("|")
        b = line.find("/")
        p = len(line[:o])
        q = len(line[b:])
        m.write(str(p) + "\n") or (str(q) + "\n") 

    f.close()
    m.close() 

print(count("ippr.txt", "outp5.txt"))

I need to count the character before this sign(|) and after this sign (/) in this text(“ippr.txt”):

Mmmm mm | ppp ppppp pppp
Ll lllll/ddd dddd ddd dddd
Bbbbb bbb bbbb|yyyyy yyy yyy yyyyyyyy

It should print 10 / 17 / 14 (on three different lines), but I get 10 / 26 / 14

You could print out the characters counted and compare to what you think should be counted

You might find it helpful to print out strings like this:

print(repr(s))

It’ll include the surrounding quotes, but more importantly it’ll display newlines as \n and similar for other strange characters.

(Windows newlines look like this: \r\n (or maybe the other way around), which is one possible explanation for extra characters)

Converting it to list might make it easier to tell the characters apart since you’ll get one per list element:

print(list(s))