I'm looping through a user's input if the input is not equated to an integer. I'm using a try: except value error
, I get an error message saying:
UnboundLocalError: local variable 'averageHeartRate' referenced before assignment
i think that means my looping is not working and it's going into the next stage of the if
statement, how can i fix this, i have tried adding other while True:
loops but they are not working.
def heartRate():
while True:
multiple_zone_question = input('Did you work in multiple heart zones? Answer Y for "Yes" or N for "No": ')
" i haven't finished writing this if statement"
if multiple_zone_question.lower() == 'y':
print('good')
break
" if user stayed only in one heart rate zone during exercise "
elif multiple_zone_question.lower() == 'n':
try:
"ask user for average heart rate "
avarageHeartRate = int(input('What was your Avarage Heart Rate during your exceresice? '))
except ValueError:
print("That's not an int!")
" average heart are should be no more then 3 numbers exm: 155 bpm"
if avarageHeartRate.len() > 3:
print('heart rate should be less then 200::\n Please enter a valid number')
'''else avarageHeartRate witch is an integer, multiplied by thresh
hold witch is also an integer stored outside of function (i probably
should move it inside the function right?). this will give me a
percentage (float) witch i can then store it into a SQL table as a
float int'''
else:
heartZone = avarageHeartRate /threshhold
return heartZone
"if multiple_zone_question is not y or n "
elif multiple_zone_question.lower() != 'y' or 'n' :
print("Invalid entry: please enter Y or N")