mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-14 05:06:55 +01:00
WIP: part 4 of module 6
This commit is contained in:
6
06/alchemy/grimoire/__init__.py
Normal file
6
06/alchemy/grimoire/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
from .spellbook import record_spell
|
||||||
|
from .validator import validate_ingredients
|
||||||
|
|
||||||
|
__version__ = "1.0.0"
|
||||||
|
__author__ = "Master Pythonicus"
|
||||||
|
__all__ = ["record_spell", "validate_ingredients"]
|
||||||
8
06/alchemy/grimoire/spellbook.py
Normal file
8
06/alchemy/grimoire/spellbook.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
def record_spell(spell_name: str, ingredients: str) -> str:
|
||||||
|
from .validator import validate_ingredients
|
||||||
|
|
||||||
|
validation_res = validate_ingredients(ingredients)
|
||||||
|
if validation_res == f"{ingredients} - VALID":
|
||||||
|
return f"Spell recorded: {spell_name} ({validation_res})"
|
||||||
|
else:
|
||||||
|
return f"Spell rejected: {spell_name} ({validation_res})"
|
||||||
8
06/alchemy/grimoire/validator.py
Normal file
8
06/alchemy/grimoire/validator.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
def validate_ingredients(ingredients: str) -> str:
|
||||||
|
try:
|
||||||
|
for ingredient in ingredients.split(" "):
|
||||||
|
if ingredient not in ["fire", "water", "earth", "air"]:
|
||||||
|
raise ValueError
|
||||||
|
return f"{ingredients} - VALID"
|
||||||
|
except ValueError:
|
||||||
|
return f"{ingredients} - INVALID"
|
||||||
14
06/ft_circular_curse.py
Normal file
14
06/ft_circular_curse.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
def ingredients_validation() -> None:
|
||||||
|
import alchemy.grimoire
|
||||||
|
|
||||||
|
print(
|
||||||
|
f'validate_ingredients("fire air"): {validate_ingredients("fire air")}'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
ingredients_validation()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user