This question already has an answer here:
I am required to come up with a code which summarizes the following table of outcomes regarding possibility of health risk. Activity level is input as a string and is_smoker is either True or False. The outcome is either extreme, high, medium or low.
Activity Level --- Smoker --- Non-smoker
None or sedentary --- extreme --- high
very low or low --- high --- medium
active or very active --- medium --- low
I was wondering if I can use brackets with my if and elif statements as I have done below, if not, how do I do this? Sorry about the imperfect formatting above, I am very new to this. Thanks in advance.
def health_risk(activity_level, is_smoker):
"""Function that tells the user their risk of health problems given their activity level and whether they are a smoker or not"""
if (activity_level = 'alive?' or 'sedentary') and is_smoker = True:
level = 'extreme'
elif (activity_level = 'alive?' or 'sedentary') and is_smoker = False:
level = 'high'
elif (activity_level = 'very low' or 'low') and is_smoker = True:
level = 'high'
elif (activity_level = 'very low' or 'low') and is_smoker = False:
level = 'medium'
elif (activity_level = 'active' or 'very active') and is_smoker = True:
level = 'medium'
elif (activity_level = 'active or very active') and is_smoker = False:
level = 'low'
return level
Aucun commentaire:
Enregistrer un commentaire