二手产品经理

二手产品经理

THIS IS RENO

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

Record#

  1. Continue learning about string manipulation.
  2. Manipulating strings is equivalent to manipulating arrays, as strings can be seen 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.