Python strings and if statements -


i having trouble python code. question supposed write program below code. code works fine in wing ide when run different input values steps, when submit system checks code errors shown below. in advance help. code below.

def activity_level_from_steps(steps):    """takes amount of steps , returns level of exercise equals"""     steps = int(steps)     if steps < 1:         level = 'alive?'     elif steps >= 1 , steps < 5000:         level = 'sedentary'     elif steps >= 5000 , steps < 7500:         level = 'very low'     elif steps >= 7500 , steps < 10000:         level = 'low'     elif steps >= 10000 , steps < 12500:         level = 'active'     else:         level = 'very active'      return level 

the question required solve

enter image description here

the error system checks code gives me

enter image description here

first, you'll need indent function body properly, since indentation important (tm) in python.

secondly, have indented return statement @ same level else. mean return invoked when else clause executed. since function doesn't return returns none default, function shown returning none other cases.

def activity_level_from_steps(steps):     """takes amount of steps , returns level of exercise equals"""     steps = int(steps)      if steps < 1:         level = 'alive?'     elif steps >= 1 , steps < 5000:         level = 'sedentary'     elif steps >= 5000 , steps < 7500:         level = 'very low'     elif steps >= 7500 , steps < 10000:         level = 'low'     elif steps >= 10000 , steps < 12500:         level = 'active'     else:         level = 'very active'      return level 

this can simplified, since each elif need check next step in activity stair:

    if steps < 1:         level = 'alive?'     elif steps < 5000:         level = 'sedentary'     elif steps < 7500:         level = 'very low'     elif steps < 10000:         level = 'low'     elif steps < 12500:         level = 'active'     else:         level = 'very active' 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -