File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ # exercise 9.1.1 from unit 9
2
+ '''
3
+ Write a function called are_files_equal defined as follows:
4
+
5
+ def are_files_equal(file1, file2):
6
+ The function accepts as parameters paths of two text files (strings).
7
+
8
+ The function returns true (True) if the files are identical in content, otherwise returns false (False).
9
+
10
+ An example of running the are_files_equal function with different files
11
+ >>> are_files_equal("c:\v acation.txt", "c:\work.txt")
12
+ False
13
+ '''
14
+
15
+ def are_files_equal (file1 , file2 ):
16
+ # open the first file and read its contents
17
+ with open (file1 , 'r' ) as f :
18
+ contents1 = f .read ()
19
+ # open the second file and read its contents
20
+ with open (file2 , 'r' ) as f :
21
+ contents2 = f .read ()
22
+ # compare the contents of the two files
23
+ return contents1 == contents2
24
+
25
+ # test the function
26
+ print (are_files_equal ("c:\\ vacation.txt" , "c:\\ work.txt" ))
You can’t perform that action at this time.
0 commit comments