2020-01-08 13:18:17 +00:00
|
|
|
def upper(word: str) -> str:
|
2020-05-22 06:10:11 +00:00
|
|
|
"""
|
2023-10-14 19:02:37 +00:00
|
|
|
Convert an entire string to ASCII uppercase letters by looking for lowercase ASCII
|
|
|
|
letters and subtracting 32 from their integer representation to get the uppercase
|
|
|
|
letter.
|
2020-05-22 06:10:11 +00:00
|
|
|
|
2020-01-08 13:18:17 +00:00
|
|
|
>>> upper("wow")
|
|
|
|
'WOW'
|
|
|
|
>>> upper("Hello")
|
|
|
|
'HELLO'
|
|
|
|
>>> upper("WHAT")
|
|
|
|
'WHAT'
|
|
|
|
>>> upper("wh[]32")
|
|
|
|
'WH[]32'
|
|
|
|
"""
|
2020-09-25 17:58:40 +00:00
|
|
|
return "".join(chr(ord(char) - 32) if "a" <= char <= "z" else char for char in word)
|
2020-01-08 13:18:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
from doctest import testmod
|
|
|
|
|
|
|
|
testmod()
|