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 nowThis is a popular solution!
Step by stepSolved in 3 steps with 4 images
- All I need is the main.cpp file Programming Specifications: Task: Two files have been provided (wordcounter.h and wordcount.cpp). You must open a text file, read in each word until end of file, add each word to the WordCount library and print the report. Your program must request a filename of a text file that contains words to count. You must check to see if it is a valid file and issue an error message if not and request a new file name until a valid one is entered. You must have at least one function that either passes in a parameter and at least one function that returns a value. You can have a single routine that does both. You must declare the class object properly, use AddWord() to add the word to the catalog and use PrintSummary() to produce the output. Design Considerations: The file will contain only words (no punctuation or special characters) less than or equal to 13 letters. There will be no limit to the number of words. You must open the file and read each…arrow_forwardCan you help me write the following C++ program: Add a search command to the file viewer created. Thiscommand asks the user for a string and finds the first line that containsthat string. The search starts at the first line that is currently displayedand stops at the end of the file. If the string is found, then the file willbe scrolled down so that when it is redisplayed, the line that contains thestring is the first line at the top of the window.If the string is not found, the program prints the following error messageat the top of the screen:ERROR: string X was not foundwhere X is replaced by the string entered by the user. In that case, theprogram redisplays the lines that the user was viewing before the searchcommand was executed.Modify the program as little as possible. Make sure you assign new responsibilities to the most appropriate components. Use the C++ string operation find. The file viewer code is given below: // FileViewer.cpp #include "FileViewer.h" using namespace…arrow_forwardCreate a new file (in Dev C++) and save it as lab7_XYZ.cpp (replace XYZ with your initials). In Lab 2, you created a menu for a simple calculator program. In Lab 6, you added some functionality based on the user selection. In this lab, you will add some more functionality to the program. Use loops to keep running the program until the user chooses the exit condition (9). When dividing, use a loop to validate user input, making sure the denominator (second number) is not zero. If the user enters a 0 for the second number, display an error message and keep prompting until a non-zero number is entered. 1) Add two numbers2) Subtract two numbers3) Multiply two numbers4) Divide two numbers 9) Exit program The program should: contain header comments as shown in class display a hello message before presenting the menu display the menu prompt user for selection echo the selection back to the user if the selection was invalid, display error message to user and then loop back to menu…arrow_forward
- Example problem. You have over 500 lines of code within a file that represent people. Some people(lines) are repeated within the file. Show an example program for how to ignore the repeated people(lines) using loops. The output from your program should read, "A total of # people are in the data file ."No functions can be used to complete this, includes file.readlines.arrow_forwardSummary In this lab, you write a while loop that uses a sentinel value to control a loop in a Python program. You also write the statements that make up the body of the loop. Each theater patron enters a value from 0 to 4 indicating the number of stars that the patron awards to the Guide’s featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. Instructions Make sure the file MovieGuide.py is selected and open. Write thewhile loop using a sentinel value to control the loop, and also write the statements that make up the body of the loop. Execute the program by clicking the Run button at the bottom of the screen. Input the following as star ratings: 0, 3, 4, 4, 1, 1, 2, -1 must be written with this code: """ MovieGuide.py This program allows each theater patron to enter a value from 0 to 4 indicating the number of stars that the patron awards to the Guide's featured movie of the week. The program executes…arrow_forwardThe Springfork Amateur Golf Club has a tournament every weekend. The club president has asked you to write a program that will read each player's name and score as keyboard input, and then save these as records in a file named golf.txt . First, the program should ask the user for the number of players. Then, it should ask the user for each name and score individually. The file golf.txt should be structured so that there is a line with the player's name, followed by their score on the next line. Here is an example: Emily 30 Mike 20 Jonathan 23 Look carefully at the following sample run of the program. In particular, notice the wording of the messages and the placement of spaces and colons. Your program's output must match this. Sample Run (User input shown in bold) Enter number of players :4↵ Enter name of player number 1 : Jimmy↵ Enter score of player number 1 : 30↵ Enter name of player number 2 : Carly↵ Enter score…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education