Record#
- Continue learning how to handle strings.
- Handling strings is equivalent to handling arrays, where strings can be viewed as arrays.
- Today's exercise is to print the string entered by the user, using the entered string as a color code, such as r = red.
def color(t):
if t == "b":
print("\033[34m", end="")
elif t == "g":
print("\033[32m", end="")
elif t == "r":
print("\033[31m", end="")
elif t == "y":
print("\033[33m", end="")
elif t == " ":
print("\033[0m", end="")
mytxt = input("What sentence do you want rainbow-ising?\n")
for letter in mytxt:
color(letter.lower())
print(letter, end="")