-
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
PythonPython Interview QuestionsPython Interview QuestionsenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededquestionFurther information is requestedFurther information is requested
Milestone
Description
🐍 Program 141: ASCII Capitalization
📌 Description
Create a function that takes a string as input and capitalizes a letter if its ASCII code is even and returns its lowercase version if its ASCII code is odd.
💡 Code Example
def ascii_capitalize(txt):
return ''.join([char.upper() if ord(char) % 2 == 0 else char.lower() for char in txt])
# Examples
print(ascii_capitalize("to be or not to be!")) # ➞ "To Be oR NoT To Be!"
print(ascii_capitalize("THE LITTLE MERMAID")) # ➞ "THe LiTTLe meRmaiD"
print(ascii_capitalize("Oh what a beautiful morning.")) # ➞ "oH wHaT a BeauTiFuL moRNiNg."✅ Output
To Be oR NoT To Be!
THe LiTTLe meRmaiD
oH wHaT a BeauTiFuL moRNiNg.
🧠 Explanation
- The function iterates over each character in the input string.
- It checks the ASCII value of each character using
ord(char). - If the ASCII value is even, it capitalizes the character; if the ASCII value is odd, it returns the character in lowercase.
Metadata
Metadata
Assignees
Labels
PythonPython Interview QuestionsPython Interview QuestionsenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is neededquestionFurther information is requestedFurther information is requested