Skip to content

Commit 50fc0ad

Browse files
authored
Merge pull request #129 from lironmiz/unit9-Ex9.1.1
Create unit9_ex9.1.1.py
2 parents edccc0f + c21ab88 commit 50fc0ad

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: unit9_ex9.1.1.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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:\vacation.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"))

0 commit comments

Comments
 (0)