Created
November 15, 2023 16:12
-
-
Save JTSGIT/3d786a6ef7fa0f524b340939ee47ec7c to your computer and use it in GitHub Desktop.
Kata5.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def url_encode(text): | |
""" | |
This function receives a string of words and returns that string with all the whitespace characters | |
converted to %20, except for leading and trailing whitespace. | |
""" | |
# Trim leading and trailing whitespace | |
trimmed_text = text.strip() | |
# Encode spaces using a loop | |
encoded_text = '' | |
for char in trimmed_text: | |
if char == ' ': | |
encoded_text += '%20' | |
else: | |
encoded_text += char | |
return encoded_text | |
# Testing the function with different inputs | |
print(url_encode("Lighthouse Labs")) | |
print(url_encode(" Lighthouse Labs ")) | |
print(url_encode("blue is greener than purple for sure")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment