Open In App

Health Management System using Python

Sometimes we are so busy that we are not even able to care for our body and by caring we mean fitness, food, exercises and much more, and then we think that we need to make our diet plan or exercise plan to maintain our body. So let’s make a Python script to maintain this record for us. In this program, we add our diet and exercises that we need to do, or we can save our daily diet or exercise with date and time to keep records. It also helps us to make another fitness plan.

In this program, user input their diet and exercise, and then we save the input with the date and time, so whenever the user wants they can see their routine. Following operations will be performed under this:



Approach:




def getdate():
    
    # to get date and time
    return datetime.datetime.now()




def selectname():
  
    name = {1: "Nilesh", 2: "Shanu"}
    b = {1: "Food", 2: "Exercise"}
  
    for key, value in name.items():
  
        # taking input of name
        print("Press", key, "for", value, "\n", end="")
  
    n = int(input("type here.."))
  
    if n > 2:
        print("error select 1 or 2")
        exit()
    else:
        return n




def select_file_action():
  
    a = {1: "Log", 2: "Retrieve"}
    for key, value in a.items():
  
        # taking input of function that user wants to
        # do (either log or retrieve)
        print("Press", key, "for", value, "\n", end="")
  
    x = int(input("type here.."))
    if x > 2:
        print("error select 1 or 2")
        exit()
    else:
        return x




def select_task():
  
    b = {1: "Food", 2: "Exercise"}
  
    for key, value in b.items():
  
        # ask user to choose between food and exercise
        print("Press", key, "for", value, "\n", end="")
  
    y = int(input("type here.."))
    if y > 2:
        print("error select 1 or 2")
        exit()
    else:
        return y




def action(n, x, y):
  
    # condition no 1
    if n == 1 and x == 1 and y == 1:
        value = input("type here\n")
  
        with open("nilesh food.txt", "a") as nileshfood:
  
            # printing date and time
            nileshfood.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition no 2
    elif n == 1 and x == 1 and y == 2:
  
        value = input("type here\n")
          
        # printing date and time
        with open("nilesh exercise.txt", "a") as nileshexercise:
  
            # printing date and time
            nileshexercise.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition 3
    elif n == 2 and x == 1 and y == 1:
  
        value = input("type here\n")
          
        # printing date and time
        with open("shanu food.txt", "a") as shanufood:
  
            # printing date and time
            shanufood.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition 4
    elif n == 2 and x == 1 and y == 2:
  
        value = input("type here\n")
  
        # printing date and time
        with open("shanu exercise.txt", "a") as shanuexercise:
  
            # printing date and time
            shanuexercise.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition 5
    elif n == 1 and x == 2 and y == 1:
  
        # printing date and time
        with open("nilesh food.txt", "r") as nileshfood:
  
            a = nileshfood.read()
            print(a)
  
    # condition no 6
    elif n == 1 and x == 2 and y == 2:
  
        # printing date and time
        with open("nilesh exercise.txt", "r") as nileshexercise:
  
            a = nileshexercise.read()
            print(a)
  
    # condition no 7
    elif n == 2 and x == 2 and y == 1:
  
        # printing date and time
        with open("shanu food.txt", "r") as shanufood:
  
            a = shanufood.read()
            print(a)
  
    # condition no 8
    elif n == 2 and x == 2 and y == 2:
  
        # printing date and time
        with open("shanu exercise.txt", "r") as shanuexercise:
  
            a = shanuexercise.read()
            print(a)

Below is a complete implementation.






import datetime
  
  
def getdate():
  
    # to get date and time
    return datetime.datetime.now()
  
def selectname():
    
    name = {1: "Nilesh", 2: "Shanu"}
    b = {1: "Food", 2: "Exercise"}
      
    for key, value in name.items():
  
        # taking input of name
        print("Press", key, "for", value, "\n", end="")
          
    n = int(input("type here.."))
      
    if n > 2:
        print("error select 1 or 2")
        exit()
    else:
        return n
  
  
def select_file_action():
    
    a = {1: "Log", 2: "Retrieve"}
      
    for key, value in a.items():
  
        # taking input of function that user wants to
        # do (either log or retrieve)
        print("Press", key, "for", value, "\n", end="")
  
    x = int(input("type here.."))
      
    if x > 2:
        print("error select 1 or 2")
        exit()
    else:
        return x
  
  
def select_task():
    
    b = {1: "Food", 2: "Exercise"}
      
    for key, value in b.items():
        
        # ask user to choose between food 
        # and exercise
        print("Press", key, "for", value, "\n", end="")
  
    y = int(input("type here.."))
      
    if y > 2:
        print("error select 1 or 2")
        exit()
    else:
        return y
  
  
def action(n, x, y):
    
    # condition no 1
    if n == 1 and x == 1 and y == 1:
        value = input("type here\n")
  
        with open("nilesh food.txt", "a") as nileshfood:
  
            # printing date and time
            nileshfood.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition no 2
    elif n == 1 and x == 1 and y == 2:
        value = input("type here\n")
  
        # printing date and time
        with open("nilesh exercise.txt", "a") as nileshexercise:
  
            # printing date and time
            nileshexercise.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition 3
    elif n == 2 and x == 1 and y == 1:
        value = input("type here\n")
  
        # printing date and time
        with open("shanu food.txt", "a") as shanufood:
  
            # printing date and time
            shanufood.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition 4
    elif n == 2 and x == 1 and y == 2:
        value = input("type here\n")
  
        # printing date and time
        with open("shanu exercise.txt", "a") as shanuexercise:
  
            # printing date and time
            shanuexercise.write(str([str(getdate())]) + ": " + value + "\n")
            print("successfully written")
  
    # condition 5
    elif n == 1 and x == 2 and y == 1:
  
        # printing date and time
        with open("nilesh food.txt", "r") as nileshfood:
            a = nileshfood.read()
            print(a)
  
    # condition no 6
    elif n == 1 and x == 2 and y == 2:
  
        # printing date and time
        with open("nilesh exercise.txt", "r") as nileshexercise:
            a = nileshexercise.read()
            print(a)
  
    # condition no 7
    elif n == 2 and x == 2 and y == 1:
  
        # printing date and time
        with open("shanu food.txt", "r") as shanufood:
            a = shanufood.read()
            print(a)
  
    # condition no 8
    elif n == 2 and x == 2 and y == 2:
  
        # printing date and time
        with open("shanu exercise.txt", "r") as shanuexercise:
            a = shanuexercise.read()
            print(a)
  
  
n = selectname()
x = select_file_action()
y = select_task()
action(n, x, y)

Output:


Article Tags :