Lab Exam II (November 19, 2025)
Baseball Teams and Games
Consider the following data describing baseball teams and results of games:$ more teams.dat Braves:Atlanta:ATL Cardinals:Saint Louis:STL Cubs:Chicago:CHC Diamondbacks:Arizona:ARI Indians:Cleveland:CLE $ more games.dat 2004-03-20:ARI:CHC:10:11 2004-03-23:ATL:STL:0:1 2004-03-27:STL:CHC:7:9 2004-03-27:CLE:ATL:1:0 2004-03-30:ATL:CHC:10:5 2004-04-01:CLE:ARI:8:8 2004-04-15:ARI:ATL:3:11 2004-04-17:CLE:STL:7:11 2004-04-20:STL:ARI:10:12 2004-04-22:CHC:CLE:7:4 2004-04-24:CHC:ARI:7:12 2004-04-29:STL:ATL:2:10 2004-05-01:ATL:CLE:14:14 2004-05-01:CHC:STL:10:0 2004-05-04:CHC:ATL:10:8 2004-05-04:ARI:CLE:8:7 2004-05-08:ATL:ARI:6:8 2004-05-13:STL:CLE:3:6 2004-05-15:ARI:STL:7:13 2004-05-15:CLE:CHC:6:8 2004-05-18:ARI:CHC:13:5 2004-05-22:ATL:STL:3:6Rows in teams.dat contain team name, team location, and team code, whereas rows in games.dat contain game date, visiting team code, home team code, visiting team score, and home team score.
We have the following two classes to represent this data as objects:
class Team: # constructor def __init__(self,tn,tcy,tcd): self.tname = tn self.tcity = tcy self.tcode = tcd self.vgames = [] # stores pointers to Game objects in which team played as visiting team self.hgames = [] # stores pointers to Game objects in which team played as home team class Game: # constructor def __init__(self,gd,vt,ht,vs,hs): self.gdate = gd self.vteam = vt # stores pointer to visiting Team object self.hteam = ht # stores pointer to home Team object self.vscore = vs # visiting team score self.hscore = hs # home team score
Figure illustrating one Game object with the two Team objects participating in the game.
Templates for the 3 files are given below:
Complete the above files (replace "pass" by code in Team.py and Baseball.py). The program essentially reads data from the two input files and constructors Team and Game objects, connects them with pointers and maintains a dictionary of Team objects identified by team code. The main program then proceeds to print the "standings" table as shown in sample run.
Sample Run:
$ python3 Baseball.py data LEAGUE STANDINGS TEAM WINS LOSSES TIES PCT ----------------------------- CHC 6 3 0 0.667 ARI 5 3 1 0.611 STL 4 5 0 0.444 ATL 3 5 1 0.389 CLE 2 4 2 0.375 ----------------------------- $
Lab Exam Policy
This is a closed-book exam! You may only have your cheat sheet and your IDE open. You may not use an internet browser to research the solution. There is only one programming question. Please read the question carefully. You will have 1 hour and 40 minutes to complete this exam. Note: Please leave time to submit your code using the following command on the tinman server:sudo handin1301 e2 Baseball.py Team.py Game.pyTo transfer the file to tinman, you may use FileZilla OR the following procedure: Open a Terminal/Powershell Window. cd into the folder containing piem.py. Then, type the following command (replace userid with your campusid):
sftp userid@tinman.cs.gsu.eduyou will be asked for your password; type it in (you may have to say "yes" to a question before password). once you see the sftp prompt, transfer the file as follows:
put Baseball.py put Team.py put Game.pyThen make sure you exit the sftp program:
exit