IT 117: Introduction to Scripting
Homework 11
Due
Thursday, October 30th at 11:59 PM
What You Need to Do
- Create the script hw11.py
- Make sure it obeys the rules in
Rules for Homework Scripts
- Make sure the script has a hashbang line and is executable
- Move it to an an hw11
directory on pe15.cs.umb.edu
Setup On Your Machine
- Open a text editor.
I would suggest the text editor built into the program IDLE
.
- Save the file as hw11.py
Specification
- This script must contain two classes
- Baseball_Game is a subclass
of Game
- Game must have the
following attributes
- date
- home_team
- opponent
- home_score
- opponent_score
- All these attributes must be hidden
- Game must have the following
methods
- __init__
- get_date
- get_home_team
- get_home_score
- get_opponent
- get_opponent_score
- __str__
- winner
- Baseball_Game must have
the following attribute
- This attribute must be hidden
- Baseball_Game must have
the following methods
- __init__
- __str__
- get_winning_pitcher
Game Methods
__init__
- Header
def __init__(self, date, home_team, opponent, home_score, opponent_score):
- This method should assign values to all attributes
- The attributes are hidden
gate_date
- Header
def get_date(self):
- This method should return the value of the
date attribute
get_home_team
- Header
def get_home_team(self):
- This method should return the value of the
home_team attribute
get_home_score
- Header
get_home_score(self):
- This method should return the value of the
get_home_score attribute
get_opponent
- Header
get_opponent(self):
- This method should return the value of the
get_opponent attribute
get_opponet_score
__str__
- Header
def __str__(self):
- This method must return a string containing the values
of all attributes
winner
- Header
def winner(self):
- This method must return the name of the winning team
Baseball_Game Methods
__init__
- Header
def __init__(self, date, home_team, opponent, home_score, opponent_score, winning_pitcher):
- This method should assign values to all attributes
- The attributes are hidden
get_winning_pitcher
__str__
- Header
def __str__(self):
- This method must return a string containing the values
of all attributes
Test Code
- Your script must contain the following statements
- They should appear at the bottom of your script
game_1 = Game("2007-10-24", "Red Sox", "Rockies", 13, 1)
print(game_1)
print(game_1.get_date())
print(game_1.get_home_team())
print(game_1.get_home_score())
print(game_1.get_opponent())
print(game_1.get_opponent_score())
print(game_1.winner())
game_2 = Baseball_Game("2007-10-24", "Red Sox", "Rockies", 13, 1, "Josh Beckett" )
print(game_2)
print(game_2.get_winning_pitcher())
Output
- The output should look something like this
2007-10-24: Red Sox 13, Rockies 1
2007-10-24
Red Sox
13
Rockies
1
Red Sox
2007-10-24: Red Sox 13, Rockies 1, Winning pitcher: Josh Beckett
Josh Beckett
Suggestions
- Write this script in stages
- Test your script at each step
- Print the steps below
- And check them off as you finish each one
-
Create the file hw11.py.
Write the class header for Game.
Write the constructor for this class.
Copy the test code to the bottom of the script.
Comment out all line in the test code except the first.
You comment out a line by making # the first character on the line.
Run the script.
Fix any errors you find.
-
Write __str__.
Remove the # from the 2nd line of the test code.
Run the script.
Fix any errors you find.
-
Write get_date.
Remove the # from the 3rd line of the test code.
Run the script.
Fix any errors you find.
-
Write get_home_team.
Remove the # from the 4th line of the test code.
Run the script.
Fix any errors you find.
-
Write get_home_score.
Remove the # from the 5th line of the test code.
Run the script.
Fix any errors you find.
-
Write get_opponent.
Remove the # from the 6th line of the test code.
Run the script.
Fix any errors you find.
-
Write get_opponent_score.
Remove the # from the 7th line of the test code.
Run the script.
Fix any errors you find.
-
Write winner.
Remove the # from the 8th line of the test code.
Run the script.
Fix any errors you find.
-
Write the class header for Baseball_Game.
Write the constructor for this class.
Remove the # from the 9th line of the test code.
Run the script.
Fix any errors you find.
-
Write __str__.
Remove the # from the 10th line of the test code.
Run the script.
Fix any errors you find.
-
Write get_winning_pitcher.
Remove the # from the last line of the test code.
Run the script.
Fix any errors you find.
Testing on Your Machine
- Open IDLE
- Use the Open command in IDLE to open hw11.py
- Under the Run menu, select Run Module
- Your output should look something like this
2007-10-24: Red Sox 13, Rockies 1
2007-10-24
Red Sox
13
Rockies
1
Red Sox
2007-10-24: Red Sox 13, Rockies 1, Winning pitcher: Josh Beckett
Josh Beckett
Copy the Script to Unix
- Open FileZilla and connect to
pe15.cs.umb.edu
- Go to your it117 directory
- Go to your hw directory
- Right-click in the whitespace inside the
hw directory
- Enter hw11 in the dialog box
- Click and drag your script from the bottom left panel
to the bottom right panel
- Right-click on the file and select "Permissions" from
the menu
- Enter 755 in the box provided
- This will make the script executable
Testing the Script on Unix (Optional)
- Connect to pe15.cs.umb.edu
using an ssh client like putty.exe (Windows)
or ssh (Mac)
- Go to the directory for this exercise
cd it117/hw/hw11
- Run this script
hw11.py
- You should see something like this
2007-10-24: Red Sox 13, Rockies 1
2007-10-24
Red Sox
13
Rockies
1
Red Sox
2007-10-24: Red Sox 13, Rockies 1, Winning pitcher: Josh Beckett
Josh Beckett
Copyright © 2023 Glenn Hoffman. All rights reserved. May not be reproduced without permission.