IT 117: Introduction to Scripting
Homework 10

Due

Sunday, November 17th at 11:59 PM

Deliverables

There is one deliverable for this assignment

Make sure the script obeys all the rules in the Script Requirements page.

Specification

In your hw10.py define the class Stamp that has the following attributes All the attributes in this class MUST be hidden.

The class must have the following methods

__init__

This method must have the following header:

def __init__(self, name, country, issued):
Both issued and value must be integers.
The constructor should set the value of value to 0.

get_name

This method must have the following header:

def get_name(self):
Returns the name of the stamp.

get_country

This method must have the following header:

def get_country(self):
Returns the country that issued the stamp.

get_issued

This method must have the following header:

def get_issued(self):
Returns the year the stamp was issued.

get_value

This method must have the following header:

def get_value(self):
Returns the value of the stamp.

set_value

This method must have the following header:

def set_value(self, value):
Assigns a value to the value attribute.
The value must be an integer.

__str__

This method must have the following header:

def __str__(self):
Returns a string containing all attribute values.

__gt__

This method must have the following header:

def __gt__(self, other):
Returns True if the the object's value for value is greater than the other object's value for value.

__lt__

This method must have the following header:

def __lt__(self, other):
Returns True if the the object's value for value is less than the other object's value for value.

__eq__

This method must have the following header:

def __eq__(self, other):
Returns True if the the object's value for value is equal to the other object's value for value.

__ne__

This method must have the following header:

def __ne__(self, other):
Returns True if the the object's value for value is not equal to the other object's value for value.

Script for this assignment

Open an a text editor and create the file hw10.py.

You can use the editor built into IDLE or a program like Sublime.

Test Code

Your hw10.py file must contain the following test code at the bottom of the file:

s1 = Stamp("1c Benjamin Franklin Z Gril", "US", 1868)
print(s1.get_name())
print(s1.get_country())
print(s1.get_issued())
print(s1.get_value())
s1.set_value(935000)
print(s1.get_value())
s2 = Stamp("3c George Washington w/ B Gril", "US", 1867)
s2.set_value(900000)
print(s2)
print("s1 > s2  :", s1 > s2)
print("s1 < s2  :", s1 < s2)
print("s1 == s2 :", s1 == s2)
print("s1 != s2 :", s1 != s2)

You should see

$ ./hw10.py 
1c Benjamin Franklin Z Gril
US
1868
0
935000
3c George Washington w/ B Gril, US, 1867, $900000
s1 > s2  : True
s1 < s2  : False
s1 == s2 : False
s1 != s2 : True

Suggestions

Write this program in a step-by-step fashion using the technique of incremental development .

In other words, write a bit of code, test it, make whatever changes you need to get it working, and go on to the next step.

  1. Create the file hw10.py.
    Write the class header for Stamp.
    Write the constructor for this class.
    Make sure the constructor sets the value for each attribute, including value.
    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.
  2. Create get_name.
    Uncomment the 2nd line of the test code by removing the #.
    Run the script.
    Fix any errors you find.
  3. Create get_country.
    Uncomment the 3rd line of the test code.
    Run the script.
    Fix any errors you find.
  4. Create get_issued.
    Uncomment the 4th line of the test code.
    Run the script.
    Fix any errors you find.
  5. Create get_value.
    Uncomment the 5th line of the test code.
    Run the script.
    Fix any errors you find.
  6. Create set_value.
    Uncomment the next two lines in the test code.
    Run the script.
    Fix any errors you find.
  7. Create __str__.
    Uncomment the next three lines of the test code.
    Run the script.
    Fix any errors you find.
  8. Create __gt__ which returns True if the value of the object is greater than the value of the other object.
    Uncomment the next line of the test code.
    Run the script.
    Fix any errors you find.
  9. Create __lt__ which returns True if the value of the object is less than the value of the other object.
    Uncomment the next line of the test code.
    Run the script.
    Fix any errors you find.
  10. Create __eq__ which returns True if the value of the object is equal the value of the other object.
    Uncomment the next line of the test code.
    Run the script.
    Fix any errors you find.
  11. Create __ne__ which returns True if the value of the object is not equal the value of the other object.
    Uncomment the next line of the test code.
    Run the script.
    Fix any errors you find.

Testing on Your Machine

Copy the file to Unix

Make the File Executable

Copyright © 2021 Glenn Hoffman. All rights reserved. May not be reproduced without permission.