[Tutor] question about the an exercise in <core python programing> (including the discription about the exercise)

Alan Gauld alan.gauld at btinternet.com
Wed Jan 4 15:36:57 CET 2012


On 04/01/12 14:13, David Palao wrote:
> Hi,
> some hints:
> 1) strings are iterables

And so are files.... ;-)

> 2) help(zip)
> 3) help(enumerate)

>     Write a program that compare the two files given by users. If the
>     two files' content is equal, just print "equal". Else, print the
>     rows And column number of the first different position.

In pseudocode you could do:

f1 = open(file1)
f2 = open(file2)
lineNum = 1
while True:
    line = f1.readline()
    if line != f2.readline():
         print lineNum, " : ", line
         exit
    else:
        lineNum += 1
print "equal"


But there other approaches you could use.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list