Skip to content

Instantly share code, notes, and snippets.

Created June 14, 2023 20:27
Show Gist options
  • Save stephengruppetta/9a05569222e87d923d03c5247e121f6a to your computer and use it in GitHub Desktop.
Save stephengruppetta/9a05569222e87d923d03c5247e121f6a to your computer and use it in GitHub Desktop.
import random
class Wizard:
def __init__(self, name, patronus, birth_year): = name
self.patronus = patronus
self.birth_year = birth_year = None
self.wand = None
self.skill = 0.2 # 0.0 (bad) to 1.0 (good)
def increase_skill(self, amount):
self.skill += amount
if self.skill > 1.0:
self.skill = 1.0
def assign_wand(self, wand):
self.wand = wand
print(f"{} has a {self.wand} wand.")
def assign_house(self, house): = house
def cast_spell(self, spell):
if self.wand:
effect = self.wand.cast_spell(spell, self)
if effect:
print(f"{} cast {effect}!")
print(f"{} failed to cast {}!")
print(f"{} has no wand!")
class Professor(Wizard):
def __init__(self, name, patronus, birth_year, subject):
super().__init__(name, patronus, birth_year)
self.subject = subject
def assess_student(self, student, mark):
# ToDo: Finish writing this method
class House:
def __init__(self, name, founder, colours, animal): = name
self.founder = founder
self.colours = colours
self.animal = animal
self.members = []
self.points = 0
def add_member(self, member):
if member not in self.members:
def remove_member(self, member):
def update_points(self, points):
self.points += points
def get_house_details(self):
return {
"founder": self.founder,
"colours": self.colours,
"animal": self.animal,
"points": self.points
class Wand:
def __init__(self, wood, core, length, power=0.5):
self.wood = wood
self.core = core
self.length = length
self.power = power # 0.0 (weak) to 1.0 (strong)
def cast_spell(self, spell, wizard):
if spell.is_successful(self, wizard):
return spell.effect
return None # Explicitly return None (for readability)
class Spell:
def __init__(self, name, effect, difficulty): = name
self.effect = effect
self.difficulty = difficulty # 0.0 (easy) to 1.0 (hard)
def is_successful(self, wand, wizard):
success_rate = (
(1 - self.difficulty)
* wand.power
* wizard.skill
return random.random() < success_rate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment