upper Algorithm
The upper Algorithm, also known as the Uppercase Algorithm, is a simple yet powerful text manipulation technique that is widely used in computer programming and data processing. This algorithm is designed to convert every character in a given string or text input into its uppercase equivalent, making it easier to perform case-insensitive comparisons, sorting, or searching. The primary function of the upper Algorithm is to improve the efficiency and accuracy of text-based operations, by standardizing the case of characters and eliminating discrepancies arising from case sensitivity.
At its core, the upper Algorithm operates by iterating through each character in the input string and identifying if it is a lowercase letter. If it is, the algorithm replaces the lowercase character with its uppercase counterpart, typically by performing a simple arithmetic operation based on the character's Unicode or ASCII value. For instance, in the ASCII character set, the algorithm can subtract 32 from the value of a lowercase letter to obtain the corresponding uppercase letter's value. Once the entire input string has been processed, the upper Algorithm returns a new string that contains the converted uppercase characters. The widespread use of the upper Algorithm in various programming languages, text editors, and databases is a testament to its efficacy and importance in the digital realm.
def upper(word: str) -> str:
"""
Will convert the entire string to uppercase letters
>>> upper("wow")
'WOW'
>>> upper("Hello")
'HELLO'
>>> upper("WHAT")
'WHAT'
>>> upper("wh[]32")
'WH[]32'
"""
# converting to ascii value int value and checking to see if char is a lower letter
# if it is a capital letter it is getting shift by 32 which makes it a capital case letter
return "".join(
chr(ord(char) - 32) if 97 <= ord(char) <= 122 else char for char in word
)
if __name__ == "__main__":
from doctest import testmod
testmod()