Question: I need some help with this python program. I'm confused about how to approach question 2 and have attached a picture of what I have


I need some help with this python program. I'm confused about how to approach question 2 and have attached a picture of what I have already done.
def printToFile(): file=open("C:\\Python Spring 2021\\toolbox\\Assignment4.txt", "w+") file.write("Player Name MinsPlayed Goals Assists YellowCard ") file.write("Lionel Messi 1943 19 4 4 ") file.write("Robert Lewandowski 1864 28 6 2 ") file.write("Harry Kane 2017 14 11 1 ") file.write("Jack Grealish 1977 6 10 6 ") file.write("Christiano Ronaldo 1722 19 3 1 ") file.write("Zlatan Ibrahimovic 1102 14 1 2 ") file.write("Gerard Moreno 1735 14 2 3 ") file.write("Romelu Lukaku 1774 18 6 4 ") file.write("Kylian Mbappe 1706 18 6 3 ") file.write("Erlin Haaland 1542 17 4 2 ") printToFile() def convertAndFindData(): filetoopen=open("C:\\Python Spring 2021\\toolbox\\Assignment4.txt","r") for line in filetoopen.readlines(): linetosplit=line.split(',') print(linetosplit)
convertAndFindData()
4 4 Create a python program to do the following: 1. Create a function that would write to a file, Assignment4.txt, the following lines (Ensure that the text would have the same format as below): Player Name MinsPlayed Goals Assists Yellow Card Lionel Messi 1943 Robert Lewandowski 1864 6 Harry Kane 2017 Jack Grealish 1977 6 Cristiano Ronaldo Zlatan Ibrahimovic 1102 Gerard Moreno 1735 Romelu Lukaku 1774 Kylian Mbappe 1706 Erlin Haaland 19 28 14 2 1 6 1 1722 11 10 3 1 2 6 6 4 19 14 14 18 18 17 2 3 3 2 1542 Once the data is written in the text, close the file. 2. Create another function that would read the file you just created with the following info. Convert the data in the file into a list and close the file. Then do the following: a. Print all the players that played more than 1700 minutes. b. Print all the players that have more than 8 goals. c. Print all player name Ronaldo if it exists. d. Print player name Kane if it exists. 3. Create another function that would parse the file so it would only print the names of the players. Edef printToFile(): file=open("C:\\Python Spring 2021\\toolbox\\Assignment4.txt", "w+") file.write("Player Name MinsPlayed Goals Assists YellowCard ") file.write("Lionel Messi 1943 19 4 4 ") file.write("Robert Lewandowski 1864 28 6 2 ") file.write("Harry Kane 2017 14 11 1 ") file.write("Jack Grealish 1977 6 10 6 ") file.write("Christiano Ronaldo 1722 19 3 1 ") file.write("Zlatan Ibrahimovic 1102 14 1 2 ") file.write("Gerard Moreno 1735 14 2 3 ") file.write("Romelu Lukaku 1774 18 6 4 ") file.write("Kylian Mbappe 1706 18 6 3 ") file.write("Erlin Haaland 1542 17 4 2 ") printToFile() Edef convertAndFindData(): filetoopen=open("C:\\Python Spring 2021\\toolbox\\Assignment4.txt","r") for line in filetoopen.readlines(): linetosplit-line.split(',') print(linetosplit)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
