answer.
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
TiliK225
6 days 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:
ivann1987 [930]6 days ago
7 0

Answer:

I am crafting a Python function:

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

with open(filename, "r") as read: #the open() function is employed to access the file in read mode

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

for line in lines: #iterates through every line of the file

if not '!' in line: #checks if a line lacks an exclamation mark

return False # returns False if a line does not include an exclamation point

return True # returns true if an exclamation mark is present in the line

print(angry_file_finder("file.txt")) invokes the angry_file_finder function by supplying a text file name to it

Explanation:

The angry_file_finder function accepts a filename as its parameter. It opens this file in read mode utilizing the open() method with "r". Then it reads every line using the readline() function. The loop checks each line for the presence of the "!" character. If any line in the file lacks the "!" character, the function returns false; otherwise, it returns true.

There is a more efficient way to write this function without using the 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"))

The revised method opens the file in reading mode and directly uses a for-loop to traverse through each line to search for the "!" character. In the for-loop, the condition checks if "!" is absent from any line in the text file. If it is missing, the function returns False; otherwise, it returns True. This approach is more efficient for locating a character in a file.

You might be interested in
In cell F15, insert a function that will automatically display the word Discontinue if the value in cell D15 is less than 1500,
ivann1987 [930]

Answer:

=IF(D15<1500, "Discontinue", "No Change")

Explanation:

In an Excel environment, you should navigate to cell F15 and apply the IF function. The structure of the IF function is

IF(<condition>, <value if true>, <value if false>)

Your condition is placed before the first comma, which is D15 < 1500.

The second segment, located before the second comma, is the text to display when D15 is below 1500, which is "Discontinue".

Finally, the last part should show text if D15 is 1500 or higher, which is "No Change".

The complete formula can be expressed as =IF(D15<1500, "Discontinue", "No Change")

3 0
1 month ago
Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the arr
Rzqust [894]

Answer:

c. The pivot could either be 7 or 9.

Explanation:

When sorting an array of eight integers through quicksort, the first partitioning indicates that either 7 or 9 may serve as the pivot. Observing the array, it is specifically 7 and 9 that occupy their correct positions within the ordered array. All integers preceding 7 and 9 are lesser, and all numbers following them are greater. Therefore, it suggests that the pivot is located between 7 and 9.

6 0
20 days ago
For Adults/Adolescents, you should call/activate EMS: Before providing CPR. After providing CPR for 2 minutes. After an AED has
Natasha_Volkova [897]

Answer:

Before administering CPR is the correct choice.

Explanation:

CPR stands for cardiopulmonary resuscitation, a procedure where the rescuer provides mouth-to-mouth ventilation and chest compressions. Anyone trained in administering CPR to adults or adolescents is expected to call or activate EMS prior to starting the cardiopulmonary resuscitation.

6 0
1 month ago
Given positive integer numInsects, write a while loop that prints that number doubled without reaching 200. Follow each number w
zubka84 [945]

Answer:

The code placed where "/*Your solution goes here */" is as follows:

while(numInsects<200) // while loop

       {

            System.out.print(numInsects+" "); // output statement

            numInsects=numInsects*2; // operation to double the value.

       }

Output:

  • If the input is 16, the result is 16 32 64 128.
  • If the input is 25, the result is 25 50 100.

Explanation:

  • The above Java code fills the section designated as "Your solution" and will operate correctly.
  • The program accepts a user input and continues to print double the value until it reaches 200 or more.
  • The while loop evaluates whether the value remains below 200. If so, the operation proceeds; otherwise, it stops.
5 0
1 month ago
A large organization is struggling to close the gaps in skill levels that exist between its employees and those from competing c
ivann1987 [930]

Answer:

C.) by enabling employees to train and enhance skills for more advanced work

Explanation:

Hope this provides assistance!

3 0
24 days ago
Other questions:
  • Susan is assisting a web designer to create a promotional web page on eco-friendly classroom designs. She uses color combination
    5·1 answer
  • How concerned are you about the security of rtos in cars smart homes and wearable technology?
    15·1 answer
  • Marien is using the Council of Science Editors (CSE) style guidelines to write her research paper. What is her most likely topic
    13·1 answer
  • for question 1-3, consider the following code what is output if the user types in 9? click all that apply A, B, C, D click all t
    13·1 answer
  • Suppose that a scheduling algorithm (at the level of short-term CPU scheduling) favors those processes that have used the least
    10·1 answer
  • The table is an excerpt from an interviewer’s notes about three applicants applying to the IT department.                
    15·1 answer
  • Fill the validateForm function to check that the phone number contains a number (use the isNaN function) and that the user name
    10·1 answer
  • An array subscript can be an expression, but only as long as the expression evaluates to what type?
    7·1 answer
  • Sara is writing a program to input her monthly phone bills and output the month name and amount for the month with maximum amoun
    7·1 answer
  • Henry, a graphic artist, wants to create posters. Which software should Henry use for this purpose?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!