Skip to content
Snippets Groups Projects
Commit e74aaa29 authored by wep23441's avatar wep23441
Browse files

new functions

parent 285a934d
No related branches found
No related tags found
No related merge requests found
"""
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()
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}")
"""
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment