二手产品经理

二手产品经理

THIS IS RENO

Learn Python Online in 100 Days - Week 4 Day 5

Record#

Catbox

  1. Today I learned how to use the os library and time, it's not really learning, just learning one way to use 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") clears the screen after execution.
  4. time.sleep is a function that makes the program wait, for example, time.sleep(3) waits 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 about 20 minutes to write. Still lacking in the usage of input.
  6. Learned a usage of input(), can be called directly, with no 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

while True:
  os.system("clear")
  print("🎵 MyPOD Music Player")
  pt = input(
    "Press 1 to Play . Press 2 to Exit . Press anything else to see the menu again."
  )
  play(pt)
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.