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()
Could someone please help me write this in Python? If time allows, it you could include...
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 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 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 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 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 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 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 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 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 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...