IT 117: Introduction to Scripting
Homework 10
Due
Thursday, October 23rd at 11:59 PM
What You Need to Do
- Create the script hw10.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 hw10
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 hw10.py
Specification
- Define the class Wine that
has the following attributes
- vineyard
- type
- year
- rating
- The script must contain XXX methods
- All the attributes in this class MUST be hidden
- The class must have the following methods
- __init__
- get_vineyard
- get_type
- get_year
- get_rating
- set_rating
- __str__
- __gt__
- __lt__
- __eq__
- __ne__
Methods
__init__
get_vineyard
- Header
def get_vineyard(self)
- This method returns the value of
vineyard
get_type
- Header
def get_type(self):
- This method returns the value of
type
get_year
- Header
def get_year(self):
- This method returns the value of
year
get_rating
- Header
def get_rating(self):
- This method returns the value of
rating
set_rating
__str__
- Header
def __str__(self):
- This method returns a string containing the attribute
values for vineyard, type and year
__gt__
- Header
def __gt__(self, other):
- This method returns
True
if the
object's value for year is greater than the other object's value
for year
__lt__
- Header
def __lt__(self, other):
- This method returns
True
if the
object's value for year is equal to the other object's value
for year
__eq__
- Header
def __eq__(self, other)
- This method returns
True
if the
object's value for year is equal to the other object's value
for year
__ne__
- Header
def __ne__(self, other):
- This method returns
True
if the
object's value for year is not equal to the other object's value
for year
Test Code
- Your script must contain the following statements
- They should appear at the bottom of your script
w1 = Wine("Pahkmeyer", "Merlot", 1999)
print("vineyard: ", w1.get_vineyard())
print("type: ", w1.get_type())
print("year: ", w1.get_year())
print("rating: ", w1.get_rating())
w1.set_rating(95)
print(w1)
print("rating: ", w1.get_rating())
w2 = Wine("Hartwell", "Merlot", 2000)
print(w2)
print("w1 > w2 :", w1 > w2)
print("w1 < w2 :", w1 < w2)
print("w1 == w2 :", w1 == w2)
print("w1 != w2 :", w1 != w2)
Output
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 hw10.py.
Write the class header for Wine.
Write the constructor for this class.
Make sure the constructor sets the value for each attribute, including rating.
The value for year should be stored as an integer.
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.
-
Create get_vineyard.
Uncomment the 2nd line of the test script by removing the #.
Run the script.
Fix any errors you find.
-
Create get_type.
Uncomment the 3rd line of the test script.
Run the script.
Fix any errors you find.
-
Create get_year.
Uncomment the 4th line of the test script.
Run the script.
Fix any errors you find.
-
Create get_rating.
Uncomment the 5th line of the test script.
Run the script.
Fix any errors you find.
-
Create set_rating.
Uncomment the next two lines of the test script.
Run the script.
Fix any errors you find.
-
Create __str__.
Uncomment the next three lines of the test script.
Run the script.
Fix any errors you find.
-
Create __gt__ which returns
True
if the year of the object is greater than the year of the other object.
Uncomment the next line of the test script.
Run the script.
Fix any errors you find.
-
Create __lt__ which returns
True
if the year of the object is less than the year of the other object.
Uncomment the next line of the test script.
Run the script.
Fix any errors you find.
-
Create __eq__ which returns
True
if the year of the object is equal the year of the other object.
Uncomment the next line of the test script.
Run the script.
Fix any errors you find.
-
Create __ne__ which returns
True
if the year of the object is not equal the year of the other object.
Uncomment the next line of the test script.
Run the script.
Fix any errors you find.
Testing on Your Machine
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 hw10 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)
Copyright © 2020 Glenn Hoffman. All rights reserved. May not be reproduced without permission.