Record#
- 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.
- Import multiple libraries, separate them with commas.
- os.system is a function that executes operating system commands, for example, os.system("clear") clears the screen after execution.
- time.sleep is a function that makes the program wait, for example, time.sleep(3) waits for 3 seconds before executing the next statement.
- 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.
- 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)