From e74aaa2995ac614d475bfccacb94cd8a70bc5cb2 Mon Sep 17 00:00:00 2001 From: wep23441 <elizabeth.mamtsits@stfc.ac.uk> Date: Thu, 27 Mar 2025 11:47:30 +0100 Subject: [PATCH] new functions --- case-5-docs/wizzard_code/string_operators.py | 53 --------------- case-5-docs/wizzard_code/wizard_calculator.py | 57 ++++++++++++++++ case-5-docs/wizzard_code/wizzard_spells.py | 66 +++++++++++++++++++ 3 files changed, 123 insertions(+), 53 deletions(-) delete mode 100644 case-5-docs/wizzard_code/string_operators.py create mode 100644 case-5-docs/wizzard_code/wizard_calculator.py create mode 100644 case-5-docs/wizzard_code/wizzard_spells.py diff --git a/case-5-docs/wizzard_code/string_operators.py b/case-5-docs/wizzard_code/string_operators.py deleted file mode 100644 index 83be357..0000000 --- a/case-5-docs/wizzard_code/string_operators.py +++ /dev/null @@ -1,53 +0,0 @@ -""" -This module contains basic string operations. -""" - -def concatenate(str1, str2): - """ - Concatenates two strings. - - Parameters: - str1 (str): The first string. - str2 (str): The second string. - - Returns: - str: The concatenation of the two strings. - """ - return str1 + str2 - -def reverse_string(string): - """ - Reverses a given string. - - Parameters: - string (str): The string to reverse. - - Returns: - str: The reversed string. - """ - return string[::-1] - -def count_vowels(string): - """ - Counts the number of vowels in a string. - - Parameters: - string (str): The string to check. - - Returns: - int: The number of vowels in the string. - """ - vowels = "aeiouAEIOU" - return sum(1 for char in string if char in vowels) - -def to_uppercase(string): - """ - Converts the string to uppercase. - - Parameters: - string (str): The string to convert. - - Returns: - str: The string in uppercase. - """ - return string.upper() diff --git a/case-5-docs/wizzard_code/wizard_calculator.py b/case-5-docs/wizzard_code/wizard_calculator.py new file mode 100644 index 0000000..f7a2478 --- /dev/null +++ b/case-5-docs/wizzard_code/wizard_calculator.py @@ -0,0 +1,57 @@ +import math + + +def summon_dragons(a, b): + return a + b + + +def vanish_trolls(a, b): + return a - b + + +def brew_potions(a, b): + return a * b + + +def cast_division_spell(a, b): + if b == 0: + raise ValueError("Attempted to split by zero โ the magic council forbids it!") + return a / b + + +def conjure_magic_circle_area(radius): + return math.pi * radius * radius + + +if __name__ == "__main__": # pragma: no cover + print("Welcome to the Wizard's Magic Calculator! ๐งโโ๏ธโจ") + print("Choose your spell:") + print("1. Summon dragons ๐") + print("2. Vanish trolls ๐น") + print("3. Brew potions ๐งช") + print("4. Cast division spell โจ") + print("5. Conjure magic circle area ๐ฎ") + + choice = input("Enter your choice (1/2/3/4/5): ") + + if choice == "5": + radius = float(input("Enter the radius of your magic circle: ")) + result = conjure_magic_circle_area(radius) + print("\nโจ Magic complete! โจ") + print(f"Circle area: {result:.2f} spells.") + else: + a = float(input("Enter the first magical number: ")) + b = float(input("Enter the second magical number: ")) + + if choice == "1": + result = summon_dragons(a, b) + elif choice == "2": + result = vanish_trolls(a, b) + elif choice == "3": + result = brew_potions(a, b) + elif choice == "4": + result = cast_division_spell(a, b) + else: + result = "The spell fizzled! Invalid choice. ๐ซง" + + print(f"The magic result is: {result}") diff --git a/case-5-docs/wizzard_code/wizzard_spells.py b/case-5-docs/wizzard_code/wizzard_spells.py new file mode 100644 index 0000000..3a2a5b1 --- /dev/null +++ b/case-5-docs/wizzard_code/wizzard_spells.py @@ -0,0 +1,66 @@ +""" +This enchanted module contains basic string spells and incantations. +""" + +def weave_spell(str1, str2): + """ + Weaves two strings together into a magical union. + + Parameters: + str1 (str): The first enchanted string. + str2 (str): The second enchanted string. + + Returns: + str: The conjured combination of the two strings. + """ + return str1 + str2 + +def reverse_time(string): + """ + Casts a reversal spell to turn the string backward in time. + + Parameters: + string (str): The string to reverse. + + Returns: + str: The reversed string, as if rewound by the hands of fate. + """ + return string[::-1] + +def count_vowel_energy(string): + """ + Summons ancient forces to count the vowels, the essence of vocal magic, within the string. + + Parameters: + string (str): The string to examine. + + Returns: + int: The number of vowels, revealed by mystical forces. + """ + vowels = "aeiouAEIOU" + return sum(1 for char in string if char in vowels) + +def invoke_uppercase(string): + """ + Casts the 'Uppercase' spell, invoking the string's full potential. + + Parameters: + string (str): The string to convert to uppercase. + + Returns: + str: The string in its most powerful, uppercase form. + """ + return string.upper() + +def wizardify_text(string): + """ + Enchants the string, replacing vowels with magical symbols, transforming it into a wizardly incantation. + + Parameters: + string (str): The string to be enchanted. + + Returns: + str: The 'wizardified' string, imbued with runes and symbols. + """ + translation = str.maketrans("aeiouAEIOU", "4@1!0^3~") + return string.translate(translation) -- GitLab