Assume that a programmer works at the office from 9am-5 pm. We have to take care of his health and remind him three things,
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.
After the user enters 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.
If you are following the lectures regularly, then I'm sure you can complete the task in no time.
Your participation is appreciated. Keep supporting and stay up to date with codewithharry
#Healthy Programmer
# 9am - 5pm
# Water - water.mp3 (3.5 litres) - Drank - log
# Eyes - eyes.mp3 - every 30 min - EyDone - log
# Physical activity - physical.mp3 every - 45 min - ExDone - log
#
# Rules
# Pygame module to play audio
Sir, please give mp3s.
Username="User" import time # import random from pygame import mixer def gettime(): import time localtime = time.asctime(time.localtime(time.time())) return localtime def log(x): z=open("Health.txt","a") z.write("At " ) z.write(str(gettime())) z.write(f":=> {x} \n ") z.close() def music(announcement,mp3,vol,stopword,logname): """ >>>>>>This function takes 05 parameters as described below: 1)announcement (str) - This takes what is to be announced while starting music 2)mp3 (mp3 filename) - This takes name of the music file. 3)vol (int) - This takes what should be the volume of the music to be played 4)stopword (str) - This takes what should be entered to stop the music 5)logname(str) - Type of activity by which your log is saved""" print(announcement) mixer.init() mixer.music.load(mp3) mixer.music.set_volume(vol) mixer.music.play() print(f"Enter {stopword} to Stop the music") while (True): z = input() if z == stopword: mixer.music.stop() log(f" {Username} {logname}") break else: print(f"Invalid input ! please Enter {stopword} to Stop music. ") continue watertime=time.time() eyetime=time.time() exetime=time.time() waterzone=27*60 eyezone=30*60 exezone=45*60 while(True): if time.localtime().tm_hour ==9 and time.localtime().tm_min==00 and time.localtime().tm_sec==00 : while(True): if time.time() - watertime >= waterzone: music("Drink water", "water.mp3", 0.7, "Drank", "Drank water") print("Done!") watertime = time.time() continue if time.time() - eyetime >= eyezone: music("Eye Exercise", "eyes.mp3", 0.7, "EyDone", "Done eye Exercise") print("Done!") eyetime = time.time() continue if time.time() - exetime >= exezone: music("Exercise time", "physical.mp3", 0.7, "ExDone", "Done Physical Exercise") print("Done!") exetime = time.time() continue if time.localtime().tm_hour == 17 and time.localtime().tm_min == 00 and time.localtime().tm_sec == 00: break if time.localtime().tm_hour == 17 and time.localtime().tm_min == 00 and time.localtime().tm_sec == 00: print("Exiting Program") time.sleep(5) break
No downloadable resources for this video. If you think you need anything, please post it in the QnA!
Any Course related announcements will be posted here