Week 2 - You Try It, Part 2 [Optional]
Python Object to model a Scratch Sprite

Code Activity

 

Earlier I showed you working code for two classes:

While we will not make a habit of having you write classes in this course - mostly just using them - I think it is worth TRYING to write a class from scratch.  In fact, let's have you write a Python version of the Scratch Sprite that we designed together last week.

Using the CreditCard and Fraction examples from above, create a Python Class called Sprite which you save in a file named Sprite.py.  This class should provide all of the data and functionality that was outlined in the class diagram shown below:

Most of these are fairly straight forward because they are simple operations.  But a few of them have some error checking and one even has (heaven forbid) trigonometry. And non-standard trigonometry at that.  Since my MAIN learning outcome with this is really just to get you to explore with the structure of Python class code, I will give you the option to create one of two versions.

 

A class called SimpleSprite in a file called SimpleSprite.py

Once you write your Sprite you can download this tester program and run it to see if your outcomes agree with what I was expecting.

 

 

If you REALLY want to test yourself:

A class called Sprite in a file called Sprite.py

Once you write your Sprite you can download this tester program and run it to see if your outcomes agree with what I was expecting.