1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
MrMuchimi
3 years ago
13

#Write a function called "angry_file_finder" that accepts a #filename as a parameter. The function should open the file, #read i

t, and return True if the file contains "!" on every #line. Otherwise the function should return False. # #Hint: there are lots of ways to do this. We'd suggest using #either the readline() or readlines() methods. readline() #returns the next line in the file; readlines() returns a #list of all the lines in the file. #Write your function here!
Computers and Technology
1 answer:
Sloan [31]3 years ago
7 0

Answer:

I am writing a Python function:

def angry_file_finder(filename):  #function definition, this function takes file name as parameter

   with open(filename, "r") as read:  #open() method is used to open the file in read mode using object read

       lines = read.readlines()  #read lines return a list of all lines in the file

       for line in lines:  #loops through each line of the file

           if not '!' in line:   #if the line does not contains exclamation mark

               return False  # returns False if a line contains no !

   return True     # returns true if the line contains exclamation mark

print(angry_file_finder("file.txt")) call angry_file_finder method by passing a text file name to it

                                                     

Explanation:

The method angry_file_finder method takes a file name as parameter. Opens that file in read mode using open() method with "r". Then it reads all the lines of the file using readline() method. The for loop iterates through these lines and check if "!" is present in the lines or not. If a line in the text file contains "!" character then function returns true else returns false.

There is a better way to write this method without using readlines() method.

def angry_file_finder(filename):

   with open(filename, "r") as file:        

       for line in file:

           if '!' not in line:  

               return False

   return True      

print(angry_file_finder("file.txt"))

Above method opens the file in read mode and just uses a for loop to iterate through each line of the file to check for ! character. The if condition in the for loop checks if ! is not present in a line of the text file. If it is not present in the line then function returns False else it returns True. This is a more efficient way to find a character in a file.

You might be interested in
It is a field that contains a unique identifier for each record in a primary table
olchik [2.2K]

Answer: C) Primary key

Explanation:

Primary key is defined as, the set of value which uniquely identifies the row of the table. The value of the primary key are used to referred the entire record as each record has different type of values for key. And each table contain only one primary key. And the primary key cannot contain the null values.

6 0
3 years ago
"The pkill command terminates _________."
Helen [10]

Answer:

d. all instances of a process with the same name matched by a regular expression

Explanation:

In Linux OS there is <em>kill</em> command that you can use to force applications to shut down. When you execute <em>kill</em> command, you are actually sending a signal to the system to force it to terminate the incorrectly behaving application.

The syntax for <em>kill</em> is:

$ kill [signal or option] PID

You have to know <em>PID</em> (Process IDentification number) of the desired process to complete this command.

The <em>pkill</em> command allows you to use advanced <em>regex</em> patterns and other matching criteria. Instead of using the <em>PID</em>, you can now terminate the application by entering the name of its process. For example, to shut down <em>Firefox</em> simply enter the command:

$ pkill firefox

Since it matches the regular expression pattern, you can also enter the name only partially, for example:

$ pkill fire

4 0
4 years ago
How do i put pics on this app ​
natka813 [3]
It says insert image I think. Or there’s a button that looks like a picture
6 0
3 years ago
Do debit cards allow you to draw funds directly from your checking accounts
LekaFEV [45]
Some of them do let you draw funds but not all debit cards
4 0
3 years ago
A custom information feel that helps users find a specific document is called
vichka [17]
A custom information feel that "HELPS USERS FIND A SPECIFIC DOCUMENT"... is what I got out of that sentence.

ANSWER: Search Box?
8 0
3 years ago
Other questions:
  • Write a program to display a message telling the educational level of a student based on their number of years of school. The us
    6·1 answer
  • Which of the following would an interactive media proffessional must likely need
    9·1 answer
  • How to remove info from a broken laptop and transfer?
    5·1 answer
  • Given that a method receives three parameters a, b, c, of type double, write some code, to be included as part of the method, th
    8·1 answer
  • Employees at a store are paid daily wages according to the following rules.
    6·1 answer
  • Define some everyday if else statements you use to determine action. What are the branches of your statement?
    12·1 answer
  • Can you get accurate
    6·2 answers
  • Implement the Dining Philosophers problem (described on pages 167-170 in the textbook (chapter 2.5.1)). Create a Graphical User
    13·1 answer
  • What does the image depict:
    14·1 answer
  • Harry needs to make a presentation on packaging prototypes for a new product. Which presentation software elements can be use to
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!