Florida Southern Seal
CSC 2280: Intro Programming
(Fall 2024)

Syllabus

LMS

Teachers

Assignments
Assignments


Other Pages

Project 11:
The Object of our Affection


Assigned: Wed Nov 20 2024
Due: 11:59:00 PM on Thu Nov 21 2024
Team Size: 1
Language: Python
Out of: 8 points


In this project, you'll create write more sophisticated functions to handle Pokemon objects.

Part 0, 2 points: It's very annoying to use six lines to create a single Pokemon object. Let's write a function, create_pokemon, which takes all the relevant parameters and returns the appropriate Pokemon object. Here are some examples:

>>> gary = create_pokemon('Gyarados', 130, ['Water', 'Flying'], 83)
>>> print_pokemon(gary)
Pokemon: Gyarados (130) HP: 83/83
>>> vandal = create_pokemon('Jigglypuff', 39, ['Normal', 'Fairy'], 44)
>>> print_pokemon(vandal)
Pokemon: Jigglypuff (39) HP: 44/44
Tester.

Part 1, 4 points: Let's write a function to revive fainted Pokemon. revive, should take a fainted pokemon and restore it to half health (rounded down). Important: lucid (non-fainted) pokemon should not have their health adjusted at all, and it should instead print out a message as shown below. Here are some examples:

>>> gary = create_pokemon('Gyarados', 130, ['Water', 'Flying'], 83)
>>> gary.hit_points = 0
>>> revive(gary)
>>> print_pokemon(gary)
Pokemon: Gyarados (130) HP: 41/83
>>> gary.hit_points = 20
>>> revive(gary)
This Gyarados is not fainted.
>>> print_pokemon(gary)
Pokemon: Gyarados (130) HP: 20/83
Tester.

Part 2, 2 points: Let's combine our expertise of lists and Pokemon and write a function that returns a list of fainted pokemon from a list of multiple pokemon, get_fainted. Here's an example:

>>> gary = create_pokemon('Gyarados', 130, ['Water', 'Flying'], 83)
>>> gary.hit_points = 0
>>> vandal = create_pokemon('Jigglypuff', 39, ['Normal', 'Fairy'], 44)
>>> pyro = create_pokemon('Flareon', 136, ['Fire'], 77)
>>> schiggy = create_pokemon('Squirtle', 7, ['Water'], 56)
>>> pyro.hit_points = 0
>>> pokemon = [gary, vandal, schiggy, pyro]
>>> fainted = get_fainted(pokemon)
>>> for p in fainted:
        print_pokemon(p)
    
Pokemon: Gyarados (130) HP: 0/83
Pokemon: Flareon (136) HP: 0/77
Tester.

Submitting your Project:

Make sure all your code is in a file labelled with your user name (everything before the @ in your school email address) followed by _projects.py all in snake_case. (For example, my file name would be: kburke_projects.py.) It's very important to name your file correctly in order for me to grade it. Make sure your code runs, then upload it to the project on Canvas. (Don't submit code that doesn't run; you won't earn any points!) Your code should include solutions to all non-zero-point problems from Project 0 onwards. If there is already a file up on Canvas, delete that before uploading the new version or make sure your new file replaces that. (Sometimes Canvas adds a number after the file name. Don't worry about that, because it's something (freaking annoying) you don't have control of. I have a script that automatically deletes that.)