Question

In: Computer Science

I need to write a function that counts the number of total wins and losses. I...

I need to write a function that counts the number of total wins and losses.

I have a text file called analysis_data.txt with 1000 lines written

Won

Loss

Won

Loss

Won

Won

...

The function need to do the following:

Opens the analysis_data.txt file and reads through all the data, counting number of 'Won' and 'Loss' words stored in the file. Returns two integers: count of wins and count of losses from the text file.

**Can't use the break statement

Solutions

Expert Solution

Let me know if you have any doubts or need any modifications.

def function():
        
    file = open("analysis_data.txt", "r") # op[ejing file in read mode]
    
    data = file.read() #reading the file and saving to variable data
    
    won = data.count("Won") # counting the occurences of won
    
    loss = data.count("Loss")# counting the occurences of loss
    
    print("Won", won) #printing won count
    
    print("Loss", loss) #printing loss count

function()

If you have any doubts, leave a comment below before rating. I'll be happy to assist you further.

Do UPVOTE this as I have put a lot of EFFORT in answering this question. It really helps me.


Related Solutions

Write a function that counts the number of times a given integer occurs in a Linked...
Write a function that counts the number of times a given integer occurs in a Linked List. What is the time complexity of your algorithm? Justify your answer in python
I need a C++ program using while loops that counts the number of characters in a...
I need a C++ program using while loops that counts the number of characters in a sentence. The user inputs a sentence and then terminates the input with either '.' or '!'. And then it needs to count and display the number of a's, e's, i's, o's, u's, and consonants. The program should read both lower and upper case. They don't want us using switch statements or string operators, and want us to us if else if statements. I have...
C programming review excerises. 1. Write a function that counts the number of lines in a...
C programming review excerises. 1. Write a function that counts the number of lines in a file, using the following declaration: int countLines(char *filename) 2. Write a program that counts the number of words in a text file. Use the command-line arguments to read the name of the file. The syntax: countwords filename.txt 3. Write a program that counts the number of words starting with the first letter ‘T’ in a text file. Using commend line argument for the text...
Write a function in lisp XIT that counts the number of items in each sub-list of...
Write a function in lisp XIT that counts the number of items in each sub-list of a list and returns the count in a list. It should only work if there are two levels of brackets in the parameter (simple lists inside the parent list). Thus:             (XIT '((A B C)))        -> (3)             (XIT '((A) (A B) (A B C))) -> (1 2 3)             (XIT '((1 2)))              -> (2)             (XIT '(1 (2 3)))...
Hello! I need to add a method that will display the total number of times the...
Hello! I need to add a method that will display the total number of times the user answered the question correctly, how many time he was right or wrong and the percentage of time they were correct in answering. import java.util.Random; import java.util.Scanner; public class Test { private static int getUserInput() { int n; Scanner scanner = new Scanner(System.in); n = scanner.nextInt(); return n; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String choice = "Yes";...
I need to write a function the will take in an array (of type double), and...
I need to write a function the will take in an array (of type double), and will return the array with all of the elements doubled while using pass-by-reference and addressing and/or pointers. This is what i have so far, but im messing up in line 31 where i call the function i believe so im not returning the correct array? please help edit. #include <iostream> #include <iomanip> using namespace std; double *doubleArray ( double arr[], int count, int SIZE);...
Here is a Problem I need to solve: 5) Write a function to determine is a...
Here is a Problem I need to solve: 5) Write a function to determine is a given word is legal. A word is illegal if it contains no vowels. For this problem, the letter Y is considered to be a legal vowel. Pass in a word to this function and it will determine if the word is legal or not. You can make the following assumptions about the word you a passing to this function. 1) The string being passed...
Write a function in R named counts. This function should take as parameters a numeric vector...
Write a function in R named counts. This function should take as parameters a numeric vector x and also a number indicating a number of bins n. The function will consider the range [min(x),max(x)], and then consider a parti- tion of this interval into n non-overlapping equally sized half open intervals: I1 = [min(x),b1),I2 = [b1,b − 2),...,In = (bn−1,max(x)]. Note that since the intervals are equally sized, the value of bi is constrained. The function will then return a...
Write an assembly code the counts the number of accuracies of the byte AAh in memory...
Write an assembly code the counts the number of accuracies of the byte AAh in memory from address 120Ah to address 130Ah. You need to use a subroutine and call it 'COUNT' to do so. You also need to provide the count in BCD if it was less than 64h so that you need to include another subroutine called 'ToBCD' to do so. assembly 8086
Write a C program that counts the number of repeated characters in a phrase entered by...
Write a C program that counts the number of repeated characters in a phrase entered by the user and prints them. If none of the characters are repeated, then print “No character is repeated” For example: If the phrase is “full proof” then the output will be Number of characters repeated: 3 Characters repeated: f, l, o Note: Assume the length of the string is 10. ###Note: the output should print exactly as it is stated in the example if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT