二手产品经理

二手产品经理

THIS IS RENO

String Processing - 38 Days - Learn Python Online in 100 Days

Record#

  1. Continue learning how to handle strings.
  2. Handling strings is equivalent to handling arrays, where strings can be viewed as arrays.
  3. 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="")
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.