This assignment is Homework 21, and is due at classtime on Friday, April 21.

Assignment

  1. Do exercises 7–12 from Section 17.6 in the Interactive Python text. (These are the first six problems on the exercises page in the Classes and Objects - Digging a Little Deeper chapter.) These problems ask you to create a Rectangle class and add various methods.

  2. Write the definition of a class called Robot that we will use as a simple model of a robot. Your class should meet the following specifications.

    Attributes: A Robot will have three attributes: a name, a build year, and a battery level.

    Methods: Implement the following methods in your Robot class:

    Sample use of a Robot:

    mike = Robot("Mike", 2016)
    print(mike.introduce()) #prints "Hello, my name is Mike."
    print(mike.battery_level) #prints 0
    mike.charge()
    print(mike.battery_level) #prints 1
    print(mike) #prints the name Mike, the year 2016, and the battery level 1

Submitting your work

After you have finished your solutions, paste them into a single Python file. Make sure that Python can run your file without error! Please use comments (lines that begin with a # symbol) to clearly state the problem numbers corresponding to your code. Save your file and upload it to the HW21 assignment on Moodle.