二手产品经理

二手产品经理

THIS IS RENO

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

Record#

Catbox

  1. Today I learned how to use the os and time libraries, but it's not really learning, just learning one usage in these two libraries.
  2. Import multiple libraries, separate them with commas.
  3. os.system is a function that executes operating system commands. For example, os.system("clear") will clear the screen.
  4. time.sleep is a function that makes the program wait. For example, time.sleep(3) will wait for 3 seconds before executing the next statement.
  5. Today's exercise is to imitate a music player, which is quite difficult for me. It took me about 20 minutes to write it. I still have a lot to learn about the usage of input.
  6. I learned a usage of input(), you can directly call it without any content in the parentheses. This way, the 3 prompts in the player can be printed, and then use input to receive user input.

CODE#

from replit import audio
import os, time

print("🎵 MyPOD Music Player")

def play(pt):
  source = audio.play_file('audio.wav')
  source.paused = False  # unpause the playback
  while True:
    pt = input(
      "Press 1 to Play . Press 2 to Exit . Press anything else to see the menu again."
    )
    if pt == "2":
      source.paused = True
      break
  # Start taking user input and doing something with it
  #input("Press 1 to Play , Press 2 to Exit ,Press anything else to see the menu again.")

while True:
  # clear the screen
  os.system("clear")
  # Show the menu
  print("🎵 MyPOD Music Player")

  # take user's input
  pt = input(
    "Press 1 to Play . Press 2 to Exit . Press anything else to see the menu again."
  )
  play(pt)
  # check whether you should call the play() subroutine depending on user's input

Translation:

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