Question
Could someone please help me write this in Python? If time allows, it you could include comments for your logic that would be of great help.

This problem involves writing a program to analyze historical win-loss data for a single season of Division I NCAA womens ba
The output should be the conference name and win-loss average for all of the conferences with the best win ratio average, one
Programming Requirements Your program should implement (at least) the following classes along with the methods specified. cla
This problem involves writing a program to analyze historical win-loss data for a single season of Division I NCAA women's basketball teams and compute from this the win ratio for each team as well as the conference(s) with the highest average win ratio. Background Whether it's football, basketball, lacrosse, or any other number of sports, loyal fans want to support their teams and also size up the competition. An important indicator of the quality of a team is its win ratio over a season, which is defined to be the fraction of wins in the total number of games that team played. Thus, if a team plays N games and wins M of them, then its win ratio is M/N. Assuming---as we will do for this problem-there are no tied games, a team with M wins and N losses has a win ratio of M/(M+N). The average win ratio for a conference in a given season is the average of the win ratios of all of the teams in that conference in that season Expected Behavior Write a program, in a file bball.py, that behaves as follows. 1. Use input () (without arguments) to read the name of an input data file. 2. Read and process the file specified (see 'Input' below for the file format). For each non- comment line in the file create a Team object from the line (see Program Structure below); parse the line to extract the appropriate data values; use these values to compute the team's win ratio; initialize the corresponding Team object appropriately. add the team to the list of teams in the appropriate conference, creating a conference if necessary 3. Compute the average win ratio for each conference and find the conference(s) that have the highest win ratio 4. Print out the results of your analysis in the format given below under Output. Some examples are shown here. Input Any line in the input file that begins with "" is a comment and should be ignored. Each non- coment line gives win-loss data for a team and has the following format: team name (one or more words), followed by conference name in parentheses (one or more words), followed by the number of wins, followed by the number of losses. For example: #Division I Women's Basketball: 2015-16 Season School (Conference) UConn (AAC) UC Riverside (Big West) 23 St. John's (NY) (Big East) Arizona (Pac-12) Wins Losses 0 38 9 23 19 10 13 If more than one conference has the highest average win ratio, they can be printed out in any order Note that the team name may consist of multiple words, some of which may be parenthesized, e.g., "St. John's (NY)". The conference name is given by the rightmost parenthesized group of words in the line.
The output should be the conference name and win-loss average for all of the conferences with the best win ratio average, one conference per line, in the following format (the simplest way to get this into your code without any mistakes is to copy-paste it into your program and then editing the variable names appropriately) " ".format (conf_name, conf_win_ratio_avg) where conf_name is the name of a conference and conf_win_ratio_avg is the average win ratio for that conference. Some examples are shown here. Assertions Your program should use assert statements to check the following (however, see below for replacements for asserts in situations where asserts are difficult to state) For each method, any pre-conditions on the arguments for that method. The assert should be placed at or very soon after the beginning of the method For each loop that either () computes a value; or (ii) transforms some data, at least one assert that holds in the body of the loop. You can choose what the invariant is, but it must be something that reflects the computation of the loop; and ois not simply a statement of the iteration condition (or some expression whose value follows directly from the iteration condition) Asserts are not necessary for loops that neither compute values nor transform data, e.g., loops that simply read in data or print out results This level of assertion-checking is almost certainly overkill, but we'll do this for a little while in order to get more experience with pre-conditions and loop invariants and to practise working with assert statements Try to make your asserts as precise and specific as you can Replacements for asserts In some situations, it may be difficult or impossible to write an assert that captures what you want to capture. In such situations, in place of an assert you can write a comment giving the invariant or assumption you want to state. Such a comment should be written as follows ## # INVARIANT: .. . your invariant in English and/or Python or ... your assumption in English and/or Python #ASSUMPTION:
Programming Requirements Your program should implement (at least) the following classes along with the methods specified. class Team An object of this class represents information about a team: namely, the team name, the conference it belongs to, and win-loss data. This class should implement the following methods: init_(self, line) line is a line read from the input file. Initializes the object with information extracted from 1line. The information stored as attributes for each team should be sufficient to implement the other methods for the team specified below name (self): returns the name of the team. conf (self): returns the conference the team belongs to. win_ratio (self) : returns the win ratio for the team str_(self): returns a string with information about the team, following format: in the .format (name, win_ratio_str) where name is the name of the team and win_ratio_stris its win ratio (as a string) class Conference An object of this class represents infformation about a set of teams, namely, the teams belonging to that conference. This class should implement the following methods init (self, conf) conf is a string giving the name of a conference. Initializes a conference object with name conf. The list of teams for the conference is initialized to be empty. contains_(self, team) team is a Team object. Returns True if team is in the list of teams for this conference; False otherwise. name (self): returns the name of the conference object add (self, team): Takes a toeam object team as argument and adds team to the list of teams associated with the object win_ratio_avg (sel f) : returns the average win ratio for the conference (a floating-point value) str_(self): returns a string with information about the conference, in the following format: " format (name, win ratio str where name is the name of the conference and win_ratio_str is its average win ratio (as a string) class ConferenceSet An object of this class represents a set of conferences. This class should implement the following methods: init_(self) : Initializes the set of conferences to be empty. add(self, team) : team is a Team object. Adds team to the appropriate conference in the list of conferences, if necessary creating a conference object for the conference of this team. best (self) returns a list of conferences that have the highest average win ratio.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ans...................

1)

def __init__(self, line):
# split a line into diffrent piece
line = line.split('(')
for i in range(0, len(line)):
assert type(line) == list
line[i] = line[i].split(')')
line[-1][-1] = line[-1][-1].split('\t')

# make a empty list to find the empty piece of str
empty = []
for i in range(0, len(line[-1][-1])):
assert type(line[-1][-1]) == list
if line[-1][-1][i] == '':
empty.append(i)
# del empty str
for i in range(len(empty)-1, 0 -1, -1):
assert line[-1][-1][empty[i]] == ''
del line[-1][-1][empty[i]]

self.__name = line[0][0]
self.__conf = line[-1][0]
# compute the win ratio
self.__win_ratio = int(line[-1][-1][-2]) / (int(line[-1][-1][-2]) + int(line[-1][-1][-1]))

# return the name of the team
def name(self):
return self.__name

# return the conf name of the team
def conf(self):
return self.__conf

# return the win ratio of the team
def win_ratio(self):
return self.__win_ratio

# str method use to print
def __str__(self):
return "{} : {}".format(self.__name, str(self.__win_ratio))

2)

class Conference:
# init the class
def __init__(self, conf):
self.__conf_name = conf
self.__conf = []
self.__avg = 0.0

# return ture is team is in this conf
def __contains__(self, team):
return team in self.__conf

# return the name of this conf
def name(self):
return self.__conf_name

# add a team to this conf
def add(self, team):
assert type(self.__conf) == list
self.__conf.append(team)

3)

def win_ratio_avg(self):
count = 0
# add win ratio of every team in that conf to count
for i in range(0, len(self.__conf)):
assert type(self.__conf[i].win_ratio()) == float
count += self.__conf[i].win_ratio()

# didided by total team
self.__avg = count / len(self.__conf)
return self.__avg

# str method use to print
def __str__(self):
return "{} : {}".format(self.__conf_name, str(self.__avg))

4)

class ConferenceSet:
# make a empty conf set
def __init__(self):
self.__conf_set = []

# add team each conf set
def add(self, team):
self.__conf_set.append(team)

5)

def best(self):
# get all conf in a set
conf_set = list(set(self.__conf_set))
large = 0
largest_conf = []
# loop trough the conf set
for i in range(0, len(conf_set)):
assert type(conf_set) == list
# if a conf's avg is large the pre lragest one
if large < conf_set[i].win_ratio_avg():
# rewirte large as it's number
large = conf_set[i].win_ratio_avg()
# rewrite largest conf as it inside of a list
largest_conf = [conf_set[i]]
# if lrage == to this conf' avg
elif large == conf_set[i].win_ratio_avg():
# append this conf to largest conf list
largest_conf.append(conf_set[i])

return largest_conf


def main():
database = input_file()
compare(database)

6)

def input_file():
file_name = input()
data = open(file_name).readlines()
# del every line start with '#'
for i in range(0, len(data)):
assert type(data) == list
if data[0][0] == '#':
del data[0]
# del every '\n' at every end of the line
for i in range(0, len(data)):
assert data[i][0] != '#'
data[i] = data[i].strip('\n')

# make a new data base
database = {}
# map team name and win ratio to each conf
for i in range(0, len(data)):
assert type(data[i]) == str
a_team = Team(data[i])
if a_team.conf() in database:
database[a_team.conf()].append([a_team, a_team.win_ratio()])
else:
database[a_team.conf()] = [[a_team, a_team.win_ratio()]]
return database

7)

def compare(database):
# init ConferenceSet
conf_set = ConferenceSet()
# add every team to conference
for conf in database:
class_conf = Conference(conf)
for i in range(0, len(database[conf])):
assert type(database) == dict
class_conf.add(database[conf][i][0])
# get the avg win ratio for each conf
avg = class_conf.win_ratio_avg()
# add each team to conf set
conf_set.add(class_conf)

#find the best ratio by calling conf_set.best()
best = conf_set.best()
for i in range(0, len(best)):
# print data
print(best[i])

main()

Add a comment
Know the answer?
Add Answer to:
Could someone please help me write this in Python? If time allows, it you could include...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help with this class and function please!!! #include <iostream> using namespace std; c...

    Need help with this class and function please!!! #include <iostream> using namespace std; class Team { string teamId; string name; string coach; Team *next; friend class teamlist; public: Team * getNext(); return next; void setNext(Team *r); next=r;    string getTeamId(); return teamId;    void setTeamId(string aTeamId); teamId = aTeamId;    string getName(); return name;    void setName(string aName); name = aName;    string getCoach(); return coach; void setCoach(string aCoach); coach = aCoach; } team list The team list is a dynamic linked list of team...

  • Can you give me this program working in C++ please 95% oo H20 LTE 9:01 PM...

    Can you give me this program working in C++ please 95% oo H20 LTE 9:01 PM ehacc hacc.edu HACC-Harrisburg Area Community Fahringer College CPS 161 Computer Science Program #7 20 points Program Due: Monday, March 21st Word Series Task: Write a program that displays the contents of the Teams txt file on the screen and prompts the user to enter the name of one of the teams. The program should then display the number of times that team has won...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • Python only please, thanks in advance. Type up the GeometricObject class (code given on the back...

    Python only please, thanks in advance. Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...

  • Write this code on python 3 only. Suppose class Student represents information about students in a...

    Write this code on python 3 only. Suppose class Student represents information about students in a course. Each student has a name and a list of test scores. The Student class should allow the user to view a student's name, view a test score at a given position, view the highest test score, view the average test score, and obtain a string representation of the student's information. When a Student object is created, the user supplies the student's name and...

  • Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user...

    Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...

  • Using c 3 File Input & Data Processing Reading data from a file is often done in order to pro...

    using c 3 File Input & Data Processing Reading data from a file is often done in order to process and aggregate it to get ad- ditional results. In this activity you will read in data from a file containing win/loss data from the 2011 Major League Baseball season. Specifically, the file data/mlb_nl_2011.txt contains data about each National League team. Each line contains a team name fol- lowed by the number of wins and number of losses during the 2011...

  • Write a python program: using class named Example. it will accept a name, the content of...

    Write a python program: using class named Example. it will accept a name, the content of the file. we will use few functions to return the name of the file, owner, set date (time it was created the file), we can also add a line and delete a line from the file. another function that returns all the data in the file. and one that deletes any previous and sets any new data user enters. we can do like Test="a","this...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember...

    Write a Python program (rock_paper_scissors.py) that allows two players play the game rock paper scissors. Remember the rules: 1. Rock beats scissors 2. Scissors beats paper 3. Paper beats rock The program should ask the users for their names, then ask them for their picks (rock, paper or scissors). After that, the program should print the winner's name. Note, the players may pick the same thing, in this case the program should say it's tie. when the user input an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT