Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For more info, when I've used Cheggs solution I get no output, no error message, just nothing. Also I need to make a file to

For more info, when I've used Cheggs solution I get no output, no error message, just nothing. Also I need to make a file to upload its not given. Could you include what your output looks like, because the typical answers on Chegg for this question is a bit vague. Also what does the file upload look like, instead of just having filename a given? Thank you!

Write a Python function to read players names and scores from a file into two parallel lists, a list of names (namesList) and a list of scores (scoresList), which will be used during the game. While reading the file, your function keeps track of the best score read so far, along with the name of the player who got that score.

After reading all of the names and scores, your function displays the highest score and that players name. For instance, if Karin had the best score and her score was 7212, your function would display:

Karin has the best score: 7212

Here is an example file:

Michael

4999

Chris

5970

Madeleine

4110

Karin

7212

Strip off the newline character before adding a name to the list of names. Assume that the filename is given when the function is called, so do not ask the user for a filename. Also, assume that the two lists are initially empty and that all scores are different: there are no ties.

Hints:

1- In a loop, read lines from the file: one read for the name and another for the score

2- Inside the loop, keep track of the maxScore and assign the maxName that has the maxScore. Append both the namesList and scoresList.

Here is the header line for the function:

def readFile(fileName, namesList, scoresList):

""" Opens and reads fileName into two parallel lists: nameList and scoreList. Also, determines and displays: the highest score, and that player's name Assumes file is in correct format: name, score, name, with each name and each score on a separate line in the file Assumes that nameList and scoreList are initially empty Assumes that all scores are different: there are no ties """

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

Describe the packaging and storage conditions for capsules.

Answered: 1 week ago