Advertisement
Guest User

Untitled

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