comp110/exercises
directory create a new folder named ex09_classes
basketball.py
in your comp110/exercises/ex09_classes
folder.BballGame
with the following specifications:
BballGame
should have a boolean
attribute called biscuits
, an int
attribute called points
, a str
attribute called winning_team
, and a str
attribute called losing_team
.Bballgame
class should have a constructor that takes in points
, winning_team
, and losing_team
. The constructor should also initialize biscuits
to be False
.check_points
, winner
, and reset_points
. The functionality of these methods should be as described below.check_points
This method does not have any parameters (besides self
) and returns None
. check_points
should check if there are at least 100 points, in which case biscuits
should be set to True
.
winner
This method does not have any parameters (besides self
) and returns a str
. If the winning team is "UNC"
and the losing team is "Dook"
, then the string "GTHD!!"
should be returned. In the case that UNC wins, but Duke is not the opposing team, winner
should return "woohoo"
. If UNC doesn’t win, return "daggum"
.
reset_points
This method does not have any parameters (besides self
) and returns an int
. reset_points
should return the current number of points, and reset the points to be 0.
animal_kingdom.py
in your comp110/exercises/ex09_classes
folder.__author__
variable.from __future__ import annotations
from typing import List
Note: The first import statement is most likely unfamiliar. The purpose of this statement is to allow the use of a class as a type inside of itself.
Animal
with the following specifications:
Animal
should have a str
attribute called species
, an int
attribute called danger_level
, and a str
attribute called emoji
.Animal
class should have a constructor that takes in species
, danger_level
and emoji
.fight
. The functionality of this method should be as described below:fight
Animal
parameter named opponent
(and self
) and returns Animal
.
fight
should return the animal with the higher danger_level
.danger_level
then the opponent should win (be returned).Team
with the following specifications:
Team
should have a str
attribute called team_name
, an List[Animal]
attribute called animals
, an int
attribute called score
.Team
class should have a constructor that takes in team_name
and animals
and initializes score
to 0.battle
and who_won
. The functionality of these methods should be as described below:battle
Team
parameter named opponent
(and self
) and returns List[Animal]
. battle
should:
animals
list in self
and opponent
are of equal size and return an empty list if not.self
and opponent
and make use of the fight method in Animal
to match up the animals at equivalent indices. For instance self.animals[0]
should fight opponent.animals[0]
.self.animals[0]
vs opponent.animals[0]
should be at index 0 of the return list.who_won
Team
parameter named opponent
(and self
) and returns str
. who_won
should:
Copy and paste the following main function add the bottom of your file:
def main() -> None:
"""Example use of Animal and Team classes."""
lion = Animal("lion", 10, "\U0001F981")
pig = Animal("pig", 3, "\U0001F437")
ram = Animal("ram", 6, "\U0001F40F")
elephant = Animal("elephant", 9, "\U0001F418")
gorilla = Animal("gorilla", 7, "\U0001F98D")
camel = Animal("camel", 4, "\U0001F42A")
team1 = Team("Hello Kitty", [lion, ram, pig])
team2 = Team("BIG", [elephant, gorilla, camel])
winners = team1.battle(team2)
print(f"{team1.team_name} vs {team2.team_name}")
for i in range(len(team1.animals)):
print(f"{team1.animals[i].emoji} vs {team2.animals[i].emoji}")
print(f"The {winners[i].species} wins!")
print(team1.who_won(team2))
The expected output should be as following:
Hello Kitty vs BIG
🦁 vs 🐘
The lion wins!
🐏 vs 🦍
The gorilla wins!
🐷 vs 🐪
The camel wins!
Team BIG won!
Animal
objects in main
and add them to the two Team
objects until the printed output of who_won
isIt was a tie!
A list of unicodes for different emojis can be found here: https://unicode.org/emoji/charts/full-emoji-list.html
Go ahead and delete any submission zips lingering around in your workspace from the previous exercise.
When you are ready to submit for grading, close out any open Python Debug Console terminals using the Trash Can and then open up a clean, new terminal.
python -m tools.submission comp110/exercises/ex09_classes
This should produce a submission timestamped with the current date/time for uploading on Gradescope.