This Boolean function takes two filenames. If any line occurs in both files, return True. If not, return False. I suggest using nested loops. With nested loops, we call the loop that is in the body of the other loop, the "inner loop". The loop that contains the inner loop is the "outer loop". Open the second file inside the outer loop: for line1 in file1: file2 = open(fname2) for line2 in file2: Python only lets you read the file once per open, so you need this order of instructions. Make sure your return False is outside of both loops. Otherwise, you will only compare the first two lines of the files. Make sure you close the file that gets read repeatedly after the inner loop but still inside the outer loop
pls code in python
plagiarism: This Boolean function takes two filenames. If any line occurs in both files, return True.
If not, return False. I suggest using nested loops. With nested loops, we call the loop that is in the
body of the other loop, the "inner loop". The loop that contains the inner loop is the "outer loop". Open
the second file inside the outer loop:
for line1 in file1:
file2 = open(fname2)
for line2 in file2:
Python only lets you read the file once per open, so you need this order of instructions. Make sure your
return False is outside of both loops. Otherwise, you will only compare the first two lines of the
files. Make sure you close the file that gets read repeatedly after the inner loop but still inside the outer
loop
.
Here is some (more complete) pseudocode to get you started:
open file 1
for line1 in file 1
open file 2
for line2 in file 2:
if line1 == line2:
return True
close file 2
return False
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images