python how to find difference between two values - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: python how to find difference between two values (/thread-15365.html) |
python how to find difference between two values - hare - Jan-14-2019 Need help in giving me an idea on how to get the output I am new to python. My input is like this: I am trying to make a output like where it prints the free and then the difference between the current free and previous free And then later on i need to determine the time when we had the most negative free value.I tried a code like this Which printed with open("summ4.txt") as f: # get first line/number nxt = int(next(f)) for n in f: print("absolute difference between {} and {} = {}" .format(n.rstrip(), nxt, abs(int(nxt) - int(n)))) # set nxt equal to the next number nxt = int(next(f,0)) a=open('summ1.txt','r').readlines() b=open('summ3.txt','r').readlines() with open('summ.txt','w') as out: for i in range(0,365): print>>out,a[i].rstrip(),b[i]. i hit .I guess my input file has a tab in the start and not able to get a difference rightly. . Any pointers on how to achieve the desired result? Thanks, Hare RE: python how to find difference between two values - Gribouillis - Jan-14-2019 It seems that you are using an old version of python, isn't that the problem? |