Course Content

Exercise 5: Health Management System

Exercise#5

The task is to create a "Health Management System." Suppose you are a fitness trainer and nutritionist. You have to deal with three clients, i.e., (Harry, Rohan, Hammad). For each client, you have to design their exercise and diet plan.

Instructions:

  • Create a food log file for each client
  • Create an exercise log file for each client.
  • Ask the user whether they want to log or retrieve client data.
  • Write a function that takes the user input of the client's name. After the client's name is entered, it will display a message as "What you want to log- Diet or Exercise".
  • Use function

 

def getdate():
           import datetime
           return datetime.datetime.now()
  • The purpose of this function is to give time with every record of food or exercise added in the file.
  • Write a function to retrieve exercise or food file records for any client.

You are advised to participate in solving this problem. This task helps you to become a good problem solver and enables you to accept the challenge and acquire new skills.

Keep supporting and stay up to date with codewithharry.

.

Code file as described in the video

# Health Management System
# 3 clients - Harry, Rohan and Hammad

def getdate():
    import datetime
    return datetime.datetime.now()

# Total 6 files
# write a function that when executed takes as input client name
# One more function to retrieve exercise or food for any client


  

Comments(4)

coder4web 1 year, 1 month ago
def getdatetime():
    import datetime
    return datetime.datetime.now()



def callHealthManagementSystem():
    print("Welcome to HMS\n");
    operation = ( "Retrive","Write" )
    user = ("Mukesh","Gautam","Praveen")
    log = ("Food_taken","Exercise_done")
    while True:
        n1 = input("What function you want to do\nPress 1 for Retrive, 2 For Write:\n")
        if int(n1) == 1 or int(n1) == 2:
            while True:
                n2 = input("Press 1 for Mukesh, 2 for Gautam, and 3 for Praveen\n")
                if int(n2) == 1 or int(n2) == 2 or int(n2) == 3:
                    while True:
                        n3 = input("Press 1 for Food, 2 for Exercise\n")
                        if int(n3) == 1 or int(n3) == 2:
                            filename = user[int(n2)-1]+"_"+log[int(n3)-1]+".txt"
                            if int(n1) == 2:
                                n4 = input("What " + log[int(n3) - 1] + " by " + user[int(n2) - 1]+":\n")
                                with open(filename,"a+") as f:
                                    f.write("["+str(getdatetime())+"] "+ n4+"\n")
                                    print("details logged successfully")
                            else:
                                try:
                                    with open(filename,"rt") as f:
                                        filecontent = f.read()
                                        print (filecontent)
                                except Exception as e:
                                    print(e)
                            break
                        else:
                            print("Wrong choice try again")
                    break
                else:
                    print("Wrong user choose try again")
            break
        else:
            print("Wrong Operation call")

callHealthManagementSystem()
Dhruva 8 months, 1 week ago
# Made by Dhruva Shaw
def getdate():
    import datetime
    return datetime.datetime.now()

def log(name,mode):
    t=""
    t = t+name
    mode = int(mode)
    if mode==1:
        t = t+"diet"+".txt"
        f = open(t,"x")
        f.close()
        with open(t,"r") as f:
            print("The previously logged diet are:")
            print(f.read())
        with open(t,"a") as f:
            diet = input("Enter the diet, seperated by commas (',')\n")
            writing = str(getdate())+str(diet)+"\n"
            f.write(writing)
            print()
            print("Sucessfully written")
            print(str(getdate()),str(diet))
            input()
    else:
        t = t+"exercise"+".txt"
        f = open(t,"x")
        f.close()
        with open(t,"r") as f:
            print("The previously logged exercise are:")
            print(f.read())
        with open(t,"a") as f:
            exercise = input("Enter the exercise, seperated by commas (',')\n")
            writing = str(getdate())+str(exercise)+"\n"
            f.write(writing)
            print()
            print("Sucessfully written")
            print(str(getdate()),str(exercise))
            input()

a,b,d=0,0,0
c = ""

def start():
    print("Which client you want to enter log")
    print("Press 1 - for 'Harry'")
    print("Press 2 - for 'Rohan'")
    print("Press 3 - for 'Hammad'")
    print("If any worng input given it will open for 'Harry'")
    global a
    global b
    global c
    global d
    try:
        a = int(input())
        if d!=1 or d!=2 or d!=3:
            a=1
    except Exception as e:
        print("This was the error",e)
        print("Now opening for 'Harry'")
        print()
        a = 1
    if a==1:
        c = "Harry"
    elif a==2:
        c = "Rohan"
    elif a==3:
        c = "Hammad"
    if a==1 or a==2 or a==3:
        print("What do you want to log in?")
        print("Press 1 - to log exercise")
        print("Press 2 - to log Diet")
        print("If nothing or wrong is entered then it will open for loging in diet")
        try:
            d = int(input())
            if d==1 or d==2 or d==3:
                log(c,d)
            else:
                log(c,1)
        except Exception as e:
            print("This was the error",e)
            print("Now opening for 'loging in the diet of",c,"'")
            print()
            log(c,1)

start()
sibu 5 months ago
harry bhai mai aap ko youtube mai bhi message kiya aur maine har aap ki website se bhi padh raha hu

code ye raha hai


def excercise(person):
    with open(person+'_excersie'+".txt",'a') as f:
        print("Prepare Excersie for ", person +":")
        excercise_Menu=input()
        p=str(getdate())
        f.write(p+" : "+excercise_Menu+"\n")
    

def diet(person):
    with open(person+"_diet"+".txt",'a') as f:
        print("Prepare diet for ", person +":")
        dietMenu=input()
        p=str(getdate())
        f.write(p+" : "+dietMenu+"\n")


def read(person):
    print("What you want to read :- Diet(press 1), Excersie(press 2):")
    readchoice=int(input())
    if readchoice==1:
        f=open(person+"_diet"+".txt",'r')
        print(f.read())
        f.close()
    else:
        f=open(person+"_excersie"+".txt",'r')
        print(f.read())
        f.close()
        
    
def getdate():
    import datetime
    return datetime.datetime.now()

print("Enter CLient Name :")
client=input()
print("what you want to log: Diet(press 1), Excersie(press 2) or Retrive the data of person(press 3)")
choice=int(input())
if choice ==1:
    diet(client)
elif choice== 3:
    read(client)
else:
    excercise(client)


    
charlie 4 months, 2 weeks ago
# Bhai badi mehnat se banaya hai please dekh lena, accha laga to reply zarur karna.
#File names - Harryexe.txt, Rohanexe.txt, Hammadexe.txt, Harrydiet.txt,Rohandiet.txt,Hammaddiet.txt.
print("#>>>>>Welcome to health management system<<<<<<#")
while(True):
    def getdate():
        import datetime
        return datetime.datetime.now()


    print("What is your client name?")
    print(" 1) 1 For Harry"
          "\n 2) 2 For Rohan"
          "\n 3) 3 For Hammad ")
    try:
        x = int(input("=>"))
    except ValueError:
        print("Invalid input! try again")
        continue
    print("What do you want to do with this profile ?")
    print(" 1) 1 For Lock something"
          "\n 2) 2 For View something")
    try:
        y = int(input("=>"))
    except ValueError:
        print("Invalid input! try again")
        continue
    print("What do you want to view/lock ?")
    print(" 1) 1 For View/lock Diet"
          "\n 2) 2 For View/lock Exercise")
    try:
        z = int(input("=>"))
    except ValueError:
        print("Invalid input! try again")
        continue
    if x == 1 and y == 1 and z == 1:
        Harry = open("Harrydiet.txt", "a")
        harrydiet = input("Enter the diet name.=>")
        Harry.write("[")
        Harry.write(str(getdate()))
        Harry.write("] => ")
        Harry.write(harrydiet)
        Harry.write(". \n")
        Harry.close()
        print("Locked succesfully...")
        print("Lock more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 2 and y == 1 and z == 1:
        Rohan = open("Rohandiet.txt", "a")
        Rohandiet = input("Enter the diet name.=>")
        Rohan.write("[")
        Rohan.write(str(getdate()))
        Rohan.write("] => ")
        Rohan.write(Rohandiet)
        Rohan.write(". \n")
        Rohan.close()
        print("Locked succesfully...")
        print("Lock more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 3 and y == 1 and z == 1:
        Hammad = open("Hammaddiet.txt", "a")
        Hammaddiet = input("Enter the diet name.=>")
        Hammad.write("[")
        Hammad.write(str(getdate()))
        Hammad.write("] => ")
        Hammad.write(Hammaddiet)
        Hammad.write(". \n")
        Hammad.close()
        print("Locked succesfully...")
        print("Lock more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 1 and y == 1 and z == 2:
        Harrye = open("Harryexe.txt", "a")
        harryexe = input("Enter the exercise name.=>")
        Harrye.write("[")
        Harrye.write(str(getdate()))
        Harrye.write("] => ")
        Harrye.write(harryexe)
        Harrye.write(". \n")
        Harrye.close()
        print("Locked succesfully...")
        print("Lock more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 2 and y == 1 and z == 2:
        Rohane = open("Harryexe.txt", "a")
        Rohanexe = input("Enter the exercise name.=>")
        Rohane.write("[")
        Rohane.write(str(getdate()))
        Rohane.write("] => ")
        Rohane.write(Rohanexe)
        Rohane.write(". \n")
        Rohane.close()
        print("Locked succesfully...")
        print("Lock more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 3 and y == 1 and z == 2:
        Hammade = open("Hammadexe.txt", "a")
        Hammadexe = input("Enter the exercise name.=>")
        Hammade.write("[")
        Hammade.write(str(getdate()))
        Hammade.write("] => ")
        Hammade.write(Hammadexe)
        Hammade.write(". \n")
        Hammade.close()
        print("Locked succesfully...")
        print("Lock more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 1 and y == 2 and z == 1:
        Reahardie = open("Harrydiet.txt")
        #k = int(input("Enter which line do you want to read? =>"))
        pop=Reahardie.read()
        print("*___________Diet info of Harry____________*")
        print("|      Date & Time           => Food Taken|")
        print(pop)
        print("___________________________________________")
        Reahardie.close()
        print("View more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 1 and y == 2 and z == 2:
        Reaharexe = open("Harryexe.txt")
        #k = int(input("Enter which line do you want to read? =>"))
        bob=Reaharexe.read()
        print("*_______Exercise info of Harry____________*")
        print("|      Date & Time           => Exercise  |")
        print(bob)
        print("___________________________________________")
        Reaharexe.close()
        print("view more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 2 and y == 2 and z == 1:
        Rearohdie = open("Rohandiet.txt")
        #k = int(input("Enter which line do you want to read? =>"))
        knob=Rearohdie.read()
        print("*___________Diet info of Rohan____________*")
        print("|      Date & Time           => Food Taken|")
        print(knob)
        print("___________________________________________")
        Rearohdie.close()
        print("view more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 2 and y == 2 and z == 2:
        Rearohexe = open("Rohanexe.txt")
        #k = int(input("Enter which line do you want to read? =>"))
        hip=Rearohexe.read()
        print("*_______Exercise info of Rohan____________*")
        print("|      Date & Time           => Exercise  |")
        print(hip)
        print("___________________________________________")
        Rearohexe.close()
        print("view more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 3 and y == 2 and z == 1:
        Reahamdie = open("Hammaddiet.txt")
        #k = int(input("Enter which line do you want to read? =>"))
        hop=Reahamdie.read()
        print("*___________Diet info of Hammad____________*")
        print("|      Date & Time           => Food Taken|")
        print(hop)
        print("___________________________________________")
        Reahamdie.close()
        print("view more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    elif x == 3 and y == 2 and z == 2:
        Reahamexe = open("Hammadexe.txt")
        #k = int(input("Enter which line do you want to read? =>"))
        tik=Reahamexe.read()
        print("*_______Exercise info of Hammad____________*")
        print("|      Date & Time           => Exercise  |")

        print(tik)
        print("___________________________________________")
        Reahamexe.close()
        print("view more (y/n) ?")
        kaka = input()
        if kaka == "y":
            print("Let's go!!!")
            continue
        if kaka == "n":
            print("Exiting")
            print("Bye")
            print(4 * "*")
            print(3 * "*")
            print(2 * "*")
            print("*")
            break
    else:
        print("Invalid input ! try again")
        continue

Resources

No downloadable resources for this video. If you think you need anything, please post it in the QnA!

Course Announcements

Any Course related announcements will be posted here