Exercise 7: Solution & First Solver
Healthy Programmer. A program we coders definitely require. The problem statement to the exercise is:
Assume that a programmer works at the office from 9-5 pm. We have to take care of his health and remind him three things,
- To drink a total of 3.5-liter water after some time interval between 9-5 pm.
- To do eye exercise after every 30 minutes.
- To perform physical activity after every 45 minutes.
Instructions:
The task is to create a program that plays mp3 audio until the programmer enters the input which implies that he has done the task.
- For Water, the user should enter “Drank”
- For Eye Exercise, the user should enter “EyDone”
- For Physical Exercise, the user should enter “ExDone”
After the user entered the input, a file should be created for every task separately, which contains the details about the time when the user performed a certain task.
Challenge:
- You will have to manage the clashes between the reminders. Such that no two reminders play at the same time.
- Use pygame module to play audio.
from pygame import mixer meaning:
- Starting the mixer mixer.init()
- Loading the song. mixer.music.load("song.mp3")
- Setting the volume. mixer.music.set_volume(0.7)
- Start playing the song. mixer.music.play()
if __name__ == “__main__” :
simple words, by using __name__, we can check whether our module is being imported or run directly.
If we run it in the same module that it is created in, then it will print “main” onto the screen; otherwise, if it is being used elsewhere, then it will print the name of its module or file it is created in.
Comments
Post a Comment