二手产品经理

二手产品经理

THIS IS RENO

Learn Python online for 100 days - Week 5, Day 1.

Record#

  1. Today I learned about the knowledge points of print. By default, print will print a newline character at the end.
    Catbox
  2. Use end=" " to customize the content printed at the end of print. For example, end="," will not print a newline at the end, but instead print a comma.
  3. In the console, \n is a newline, \t is a tab, \v is a vertical tab.
  4. Use sep=" " to customize the separator of the printed content in print. For example, sep="," will separate the content with commas.
    Catbox
    6. print('\033[?25l', end="") This statement can disable the cursor prompt in the console.
    7. print('\033[?25h', end="") This statement can enable the cursor prompt in the console.
    8. Today's exercise is to write a function that takes two parameters to control the color of the printed output. Indeed, changing the color is a one-time effort. To change it back, you need to print again, haha!

CODE#

def color(s, t):
  if s == "fen":
    print("\033[35m", t, sep="", end="")
  elif s == "hong":
    print("\033[31m", t, sep="", end="")
  elif s == "lv":
    print("\033[32m", t, sep="", end="")
  else:
    print("\033[0m", t, sep="", end="")


print("Super Subroutine")
print("With my ", end="")
color("fen", "new program")
color("r"," I can just call red('and ' ) ")
color("hong", "and"),
color("r"," that word will appear in the color I set it to .")
color("r","With no ")
color("lv", "weird gaps ")
color("r",".")
color("r","Epic")

Translation:

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.