Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-----------------------------------------------------------------------------
- # Name: Assertations practice (main.py)
- # Purpose: Showing an understanding of topics learned in class
- # Author: 620988
- # Created: 24-Oct-19
- # Updated: 11-Dec-19
- #-----------------------------------------------------------------------------
- import logging
- logging.basicConfig(filename='log.txt', level=logging.DEBUG, format=' %(asctime)s - %(levelname)s - %(message)s')
- #functions
- def oneRepMax(reps,weight):
- '''
- This function is a formula to calculate one rep max
- This function will ask user to submit their reps done and weight done to find how
- much weight they can do for 1 rep
- Parameters
- ----------
- reps done and weight done
- Returns
- -------
- float
- the value of the 1rm
- '''
- if not weight > 0 or not reps > 0:
- return ' "Soryy, could not find 1rm due to invalid number."'
- max = weight*(1+reps/30)
- return max
- assert oneRepMax(9, 200) == 260, 'Expecting someone who lifts 200 for 9 to have a 1rm of 260'
- #assert isinstance(max, string), 'Expecting a float'
- def bodyMassIndex(height,weight):
- '''
- This function is a formula to calculate one's BMI
- This function will ask user to submit weight and heigh. Using the weight and height a formula is done
- Parameters
- ----------
- weight and height
- Returns
- -------
- floats
- the value of bmi
- '''
- if not isinstance(height, (int, float)):
- raise TypeError('onerepmax expecting an int or float as input')
- if not isinstance(weight, (int, float)):
- raise TypeError('onerepmax expecting an int or float as input')
- if weight < 0 or height < 0:
- raise ValueError('Values too low for expected range ')
- # return ' "Sorry, could not find BMI due to invalid number."'
- bmi = 703*weight/(height**2)
- return bmi
- #lists that are used when inVar = 3 and 4
- assert bodyMassIndex(50, 100) == 28.12, 'Expecting someone who lifts 200 for 9 to have a 1rm of 260'
- #assert isinstance(bmi, float), 'Expecting a float'
- def menu():
- '''
- This function is a menu of options
- This function will print out a list of options
- available for the user
- Parameters
- ----------
- None
- Returns
- -------
- None
- '''
- print('''
- What do you want to do?(type integer)
- 1) Calculate 1 rep max
- 2) Calculate BMI
- 3) Log daily calorie and mood summary
- 4) View past logs
- 5) Exit app
- 6)
- ''')
- return
- assert isinstance(menu, string), 'Expecting a string'
- dailySummary = []
- dailyCals =[]
- 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.")
- #if username is a number it is invalid
- while True:
- username= str(input("Enter your username" ))
- logging.debug('the username is ' + username)
- if username.isdigit():#if statemnt
- print("invalid username, retry")
- else:
- print("Welcome back {}".format(username))
- break
- #while loop
- while True:
- try: #menu
- inVar = int(input(menu))
- except: #using the try and except (extension)
- print("invalid option try again")
- continue
- if inVar == 1:
- while True:
- try:
- repsDone= int(input("How many reps did you do"))
- weightDone= int(input("What was the weight used during this activity"))
- break
- except:
- print("invalid input, retry")
- print("Your one rep max is "+ str(oneRepMax(repsDone,weightDone)))
- elif inVar == 2:
- while True:
- try:
- weightOfUser= float(input("How much do you weigh in pounds"))
- heightOfUser= float(input("What is your height in inches"))
- break
- except:
- print("invalid input, retry")
- try:
- print("Your bmi is "+ str(bodyMassIndex(heightOfUser,weightOfUser)))
- except :
- print("invalid input, retry")
- elif inVar == 3:
- while True:
- dailySummaryEmotion = str(input("Talk about your overall daily mood: "))
- dailySummary.append(dailySummaryEmotion)
- while True:
- try:
- dailySummaryCalories = int(input("Enter your daily calorie intake as a number: "))
- except:
- print("You must enter a number")
- continue
- if dailySummaryCalories < 0:
- print("Calories must be positive!")
- continue
- break
- dailyCals.append(dailySummaryCalories)#add onto list
- 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")
- if areYouSure == "a":
- print("You are finished your daily summary, you must wait until tommorow to input your next daily summary.")
- break
- else:
- print("Sending you back to redo")
- del dailySummary[-1]
- del dailyCals[-1]
- elif inVar == 4:
- 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 ")
- if viewPastSummary == "1":
- if len(dailySummary) > 0:
- for i in range(len(dailySummary)-1,-1,-1):
- dailySummary[i] = "Here is your mood summary on day " + str(i+1) + " :" + str(dailySummary[i])
- print(dailySummary[i])
- for i in range(len(dailyCals)-1,-1,-1):
- dailyCals[i] = "Here is your calorie summary on day " + str(i+1) + " :" + str(dailyCals[i])
- print(dailyCals[i])
- else:
- print("You have yet to input anything")
- elif viewPastSummary == "2":
- 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")
- while True:
- if len(dailySummary)>0:
- i = 0
- while i < len(dailyCals):
- print(i+1)
- while True:
- pastDate = int(input("Enter day to look at."))
- pastDate = pastDate- 1 # convert to zero index
- if pastDate < 0 or pastDate >= len(dailyCals):
- print("You have no submission for this date")
- continue
- else:
- print("Here is your mood summary for that day: " + str(dailySummary[pastDate]))
- print("Here is your daily calories for that day: " + str(dailyCals[pastDate]))
- break
- break
- else:
- print("\nYou have yet to enter any data, start by doing your summary")
- else:
- print("\nenter either 1 or 2, nothing else... sending you back to the menu")
- elif inVar == 5:
- print("thank you for using the app, until next time " + username)
- break
- elif inVar == 6:
- dailyCals.sort()
- while g < len(dailyCals):
- g = g+1
- print(dailyCals[g])
- print(g+"st lowest")
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement