IT 117: Intermediate Scripting
Homework 10

Due

Sunday, April 20th at 11:59 PM

What You Need to Do

Setup On Your Machine

Specification

Test Code

Output

Suggestions

  1. Add a header for the class Pet to the script.
    Create the method header for the constructor __init__ with parameters self, name, type, and age.
    For the body of this function, use a pass statement.
    Run the script and fix any errors you find.
  2. Copy the test code to the bottom of the script.
    Comment out all the statements after
    p1 = Pet("Henry", "dog", 7)
    Add assignment statements for each of the attributes.
    Remember the attributes must be hidden.
    Run the script and fix any errors you find.
  3. Create method __str__ that returns a string containing the value of all attributes with a comma between them.
    Remember to convert age to a string.
    Remove the # from the next line in the test code.
    Run the script and fix any errors you find.
  4. Remove the assignment statement for type in the constructor.
    Replace it with an if statement that checks if the vaule of type is contained in the list ["dog", "cat"].
    If the value passes this test, set type to this value.
    If not, print an error message.
    Remove the # from the next line in the test code.
    Run the script and fix any errors you find.
  5. Remove the assignment statement for age in the constructor.
    Replace it with an try/except statement.
    Inside the try block covert the age value to an integer and set the age attribute to this value.
    in the else clause print an error message.
    Remove the # from the next line in the test code.
    Run the script and fix any errors you find.
  6. Create the accesor method get_name that returns the value of title.
    Remove the # from the next three lines in the test code.
    Run the script and fix any errors you find.
  7. Create the accesor method get_type that returns the value of type.
    Remove the # from the next line in the test code.
    Run the script and fix any errors you find.
  8. Create the accesor method get_age that returns the value of age.
    Remove the # from the next line in the test code.
    Run the script and fix any errors you find.
  9. Create the method __gt__ which has two parameters, self and other.
    This method will return the vaule of the boolean expressios asking if the age of self is greater than the age of other.
    Remove the # from the next three lines in the test code.
    Run the script and fix any errors you find.
  10. Write an if statement that checks if the age of self is greater than the age of other.
    If it is, print print a message that uses the names of the two pets to say that self is older than other.
  11. Add an elif clause that checks if the age of other is greater than the age of self.
    If it is, print a message that uses the names of the two pets to say that other is older than self.
    Run the script and fix any errors you find.
  12. Add an else clause that prints a message using the names of the two pets saying that both are the same age.
    Run the script and fix any errors you find.

Testing on Your Machine

Copy the Script to Unix

Testing the Script on Unix (Optional)

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