Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.58 KB | None | 0 0
  1. # -----------------------------------------------------------------------------
  2. # Name:        Assertations practice  (main.py)
  3. # Purpose:     Showing an understanding of topics learned in class
  4. # Author:      620988
  5. # Created:     24-Oct-19
  6. # Updated:     11-Dec-19
  7. # -----------------------------------------------------------------------------
  8. import logging
  9.  
  10. logging.basicConfig(filename='log.txt', level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
  11.  
  12. logging.info("Start of program")
  13. # functions
  14. def oneRepMax(reps, weight):
  15.     '''
  16.    This function is a formula to calculate one rep max
  17.  
  18.    This function will ask user to submit their reps done and weight done to find how
  19.    much weight they can do for 1 rep
  20.  
  21.    Parameters
  22.    ----------
  23.    reps done and weight done
  24.  
  25.    Returns
  26.    -------
  27.    float
  28.    the value of the 1rm
  29.    '''
  30.     logging.info("Start of Program")
  31.     if not weight > 0 or not reps > 0:
  32.         return ValueError(' "Soryy, could not find 1rm due to invalid number."')
  33.     max = weight * (1 + reps / 30)
  34.     logging.debug("Max weight they can do: " + str(max))
  35.     logging.info("End of program")
  36.     return max
  37.  
  38.  
  39. # assert oneRepMax(9, 200) == 260, 'Expecting someone who lifts 200 for 9 to have a 1rm of 260'
  40.  
  41.  
  42. # assert isinstance(max, string), 'Expecting a float'
  43.  
  44. def bodyMassIndex(height, weight):
  45.     '''
  46.    This function is a formula to calculate one's BMI
  47.  
  48.    This function will ask user to submit weight and heigh. Using the weight and height a formula is done
  49.  
  50.    Parameters
  51.    ----------
  52.    weight and height
  53.  
  54.    Returns
  55.    -------
  56.    floats
  57.    the value of bmi
  58.    '''
  59.     logging.info("Starting Function: bodyMassIndex")
  60.     logging.debug("height is: " + str(height))
  61.     logging.debug("weight is: " + str(weight))
  62.     if not isinstance(height, (int, float)):
  63.         raise TypeError('onerepmax expecting an int or float as input')
  64.     if not isinstance(weight, (int, float)):
  65.         raise TypeError('onerepmax expecting an int or float as input')
  66.     if weight < 0 or height < 0:
  67.         raise ValueError('Values too low for expected range ')
  68.         # return ' "Sorry, could not find BMI due to invalid number."'
  69.     bmi = 703 * weight / (height ** 2)
  70.     logging.info("Ending Function: bodyMassIndex")
  71.     return bmi
  72.  
  73. # lists that are used when inVar = 3 and 4
  74. # assert bodyMassIndex(50, 100) == 28.12, 'Expecting someone who lifts 200 for 9 to have a 1rm of 260'
  75.  
  76.  
  77. # assert isinstance(bmi, float), 'Expecting a float'
  78.  
  79. def menu():
  80.     '''
  81.    This function is a menu of options
  82.  
  83.    This function will print out a list of options
  84.    available for the user
  85.  
  86.    Parameters
  87.    ----------
  88.    None
  89.  
  90.    Returns
  91.    -------
  92.    None
  93.    '''
  94.     logging.info("Starting Function")
  95.     print('''
  96.  What do you want to do?(type integer)
  97.  
  98.  1) Calculate 1 rep max
  99.  2) Calculate BMI
  100.  3) Log daily calorie and mood summary
  101.  4) View past logs
  102.  5) Exit app
  103.  
  104.  ''')
  105.     logging.info("Ending Function")
  106.  
  107.     # assert isinstance(menu, string), 'Expecting a string'
  108.  
  109.  
  110. dailySummary = []
  111. dailyCals = []
  112.  
  113. print(
  114.     "Welcome to Johann's health app, with this app, athletes can use it to keep track of all aspects of their health so they can adjust their lifestyles.")
  115.  
  116. # if username is a number it is invalid
  117. while True:
  118.  
  119.     username = str(input("Enter your username: "))
  120.     logging.debug('the username is ' + username)
  121.     if username.isdigit():  # if statement
  122.         print("invalid username, retry")
  123.     else:
  124.         print("Welcome back {}".format(username))
  125.         break
  126. # while loop
  127. while True:
  128.     try:  # menu
  129.         menu()
  130.         inVar = int(input())
  131.         logging.debug("inputted inVar: " + str(inVar))
  132.     except ValueError:  # using the try and except (extension)
  133.         print("invalid option try again")
  134.         continue
  135.  
  136.     if inVar == 1:
  137.         while True:
  138.             try:
  139.                 repsDone = int(input("How many reps did you do"))
  140.                 weightDone = int(input("What was the weight used during this activity"))
  141.                 break
  142.             except ValueError:
  143.                 print("invalid input, retry")
  144.  
  145.         print("Your one rep max is " + str(oneRepMax(repsDone, weightDone)))
  146.  
  147.     elif inVar == 2:
  148.         while True:
  149.             try:
  150.                 weightOfUser = float(input("How much do you weigh in pounds"))
  151.                 heightOfUser = float(input("What is your height in inches"))
  152.                 break
  153.             except:
  154.                 print("invalid input, retry")
  155.         try:
  156.             print("Your bmi is " + str(bodyMassIndex(heightOfUser, weightOfUser)))
  157.         except:
  158.             print("invalid input, retry")
  159.  
  160.     elif inVar == 3:
  161.         while True:
  162.             dailySummaryEmotion = str(input("Talk about your overall daily mood: "))
  163.             dailySummary.append(dailySummaryEmotion)
  164.             while True:
  165.                 try:
  166.                     dailySummaryCalories = int(input("Enter your daily calorie intake as a number: "))
  167.                 except:
  168.                     print("You must enter a number")
  169.                     continue
  170.                 if dailySummaryCalories < 0:
  171.                     print("Calories must be positive!")
  172.                     continue
  173.                 break
  174.             dailyCals.append(dailySummaryCalories)  # add onto list
  175.  
  176.             areYouSure = input(
  177.                 "\nYou have entered entered your daily summary. Double check to see if the summary are correct. )\n Mood summary: " +
  178.                 dailySummary[-1] + "\n Today's calorie intake: " + str(dailyCals[
  179.                                                                            -1]) + "\n Enter the letter 'a' if you are confident that your summry is correct, otherwise, enter any other characters")
  180.             if areYouSure == "a":
  181.                 print(
  182.                     "You are finished your daily summary, you must wait until tommorow to input your next daily summary.")
  183.                 break
  184.             else:
  185.                 print("Sending you back to redo")
  186.                 del dailySummary[-1]
  187.                 del dailyCals[-1]
  188.     elif inVar == 4:
  189.         viewPastSummary = input(
  190.             "You have selected to view your histories. You can either look at a past date or print out your whole entire summary log. Enter 1 to print out your entire history or Enter 2 to check a specific date ")
  191.  
  192.         if viewPastSummary == "1":
  193.             if len(dailySummary) > 0:
  194.                 for i in range(len(dailySummary) - 1, -1, -1):
  195.                     dailySummary[i] = "Here is your mood summary on day " + str(i + 1) + " :" + str(dailySummary[i])
  196.                     print(dailySummary[i])
  197.                 for i in range(len(dailyCals) - 1, -1, -1):
  198.                     dailyCals[i] = "Here is your calorie summary on day " + str(i + 1) + " :" + str(dailyCals[i])
  199.                     print(dailyCals[i])
  200.             else:
  201.                 print("You have yet to input anything")
  202.  
  203.  
  204.         elif viewPastSummary == "2":
  205.  
  206.             print(
  207.                 "These are the days you can look at, with 1 being your first log. If none are showing up, you havent put anything in your summaries")
  208.             while True:
  209.                 if len(dailySummary) > 0:
  210.                     i = 0
  211.                     while i < len(dailyCals):
  212.                         print(i + 1)
  213.                     while True:
  214.                         pastDate = int(input("Enter day to look at."))
  215.                         pastDate = pastDate - 1  # convert to zero index
  216.                         if pastDate < 0 or pastDate >= len(dailyCals):
  217.                             print("You have no submission for this date")
  218.                             continue
  219.                         else:
  220.                             print("Here is your mood summary for that day: " + str(dailySummary[pastDate]))
  221.                             print("Here is your daily calories for that day: " + str(dailyCals[pastDate]))
  222.                         break
  223.                     break
  224.  
  225.                 else:
  226.                     print("\nYou have yet to enter any data, start by doing your summary")
  227.  
  228.         else:
  229.             print("\nenter either 1 or 2, nothing else... sending you back to the menu")
  230.  
  231.     elif inVar == 5:
  232.         print("thank you for using the app, until next time " + username)
  233.         break
  234.  
  235.     elif inVar == 6:
  236.         dailyCals.sort()
  237.  
  238.         while g < len(dailyCals):
  239.             g = g + 1
  240.             print(dailyCals[g])
  241.             print(g + "st lowest")
  242.             print()
  243.  
  244. logging.info("End of Program")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement