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
A user receives a phone call from a person claiming to be from technical support. This person knows the users name and that the
klasskru [66]

Answer:

This is an example of Social Engineering security threats

Explanation:

Social Engineering is a process whereby cyber attackers manipulate victims to divulge personal information. These victims are tricked to granting attackers access to valuable and confidential information.

Social Engineering is considered one of the greatest threats to organizations because it is different from hackers trying to break into a system. Social Engineers are granted legitimate access by unsuspecting victims.

Tips to help against Social Engineers.

  1. Don't be too hasty to respond.
  2. Be careful of the links you click, research on them before you click them.
  3. Don't be quick to download files that you are not sure of the source, always check before you download.
  4. Don't be quick to jump into foreign offers, as they could be the bait to getting your information.

7 0
3 years ago
If the force of gravity _ then the weight of an object will _
LenKa [72]

The weight of an object is directly perportional to value of g. which is 9.8 m/s2 . if the value is zero then the weight of that object will be zero on that surface.Watch this video to understand more about your topic.

http://googletune.com/watch?v=hPEx3gxtPK4


3 0
3 years ago
Read 2 more answers
Select the correct images Jane has to pick images that portray action photography. Which of these images would she pick? please
Scilla [17]

Answer: i think its the horse the basketball and the bike hopefully i helped

Explanation:

8 0
3 years ago
What is a tag in an HTML document?
Rashid [163]
Code that specifies how the web page should be formatted
8 0
3 years ago
Ideally, how often should you back up the data on your computer? once an hour, once a day, once a month, once a year. Please hur
Stells [14]

Explanation:

Every month or so

5 0
3 years ago
Read 2 more answers
Other questions:
  • Select the correct answer.
    8·2 answers
  • ____ port is a connection in which eight data lines transmit an entire byte of data at one moment in time.
    12·1 answer
  • Which of the following is a Federal law that provides a definition of the term cyberterrorism and under which young people prima
    7·1 answer
  • Two processes are running the same program on a computer. The operating system can set up an access restriction on the control
    7·1 answer
  • Who knows coding questions? Please help! Thanks.
    6·1 answer
  • What is the name of the file manager in Microsoft Windows?​
    5·1 answer
  • A sequential algorithm is broken into three stages
    14·2 answers
  • You are creating a program that can add up the amount of money the user spent that day. Right down to the penny! What kind of va
    12·2 answers
  • What is wrong here??
    14·1 answer
  • assuming the default gateway is connected to the internet, what type of internet access would this server have?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!