mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-13 20:56:54 +01:00
part 2 of module 6
This commit is contained in:
27
06/alchemy/potions.py
Normal file
27
06/alchemy/potions.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
def healing_potion() -> str:
|
||||||
|
from .elements import create_water, create_fire
|
||||||
|
|
||||||
|
return f"Healing potion brewed with {create_fire()} and {create_water()}"
|
||||||
|
|
||||||
|
|
||||||
|
def strength_potion() -> str:
|
||||||
|
from .elements import create_earth, create_fire
|
||||||
|
|
||||||
|
return f"Strength potion brewed with {create_earth()} and {create_fire()}"
|
||||||
|
|
||||||
|
|
||||||
|
def invisibility_potion() -> str:
|
||||||
|
from .elements import create_air, create_water
|
||||||
|
|
||||||
|
return (
|
||||||
|
f"Invisibility potion brewed with {create_air()} and {create_water()}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def wisdom_potion() -> str:
|
||||||
|
from .elements import create_water, create_fire, create_air, create_earth
|
||||||
|
|
||||||
|
res = ""
|
||||||
|
for fn in (create_water(), create_fire(), create_air(), create_earth()):
|
||||||
|
res += fn
|
||||||
|
return f"Wisdom potion brewed with all elements: {res}"
|
||||||
54
06/ft_import_transmutation.py
Normal file
54
06/ft_import_transmutation.py
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
def full_module_import() -> None:
|
||||||
|
import alchemy.elements
|
||||||
|
|
||||||
|
print(f"alchemy.elements.create_fire(): {alchemy.elements.create_fire()}")
|
||||||
|
|
||||||
|
|
||||||
|
def specific_function_import() -> None:
|
||||||
|
from alchemy.elements import create_water
|
||||||
|
|
||||||
|
print(f"create_water(): {create_water()}")
|
||||||
|
|
||||||
|
|
||||||
|
def aliased_import() -> None:
|
||||||
|
from alchemy.potions import healing_potion as heal
|
||||||
|
|
||||||
|
print(f"heal(): {heal()}")
|
||||||
|
|
||||||
|
|
||||||
|
def multiple_import() -> None:
|
||||||
|
from alchemy.elements import create_fire, create_earth
|
||||||
|
from alchemy.potions import strength_potion
|
||||||
|
|
||||||
|
print(f"create_earth(): {create_earth()}")
|
||||||
|
print(f"create_fire(): {create_fire()}")
|
||||||
|
print(f"strength_potion(): {strength_potion()}")
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
print("=== Import Transmutation Mastery ===\n")
|
||||||
|
print("Method 1 - Full module import:")
|
||||||
|
try:
|
||||||
|
full_module_import()
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
print("\nMethod 2 - Specific function import:")
|
||||||
|
try:
|
||||||
|
specific_function_import()
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
print("\nMethod 3 - Aliased import:")
|
||||||
|
try:
|
||||||
|
aliased_import()
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
print("\nMethod 4 - Multiple imports:")
|
||||||
|
try:
|
||||||
|
multiple_import()
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
print("\nAll import transmutation methods mastered!")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user