Answer:
day variable is the day number of the week which takes value 0 to 6, and then again 0 to 6 and so on.
weight variable contains the current weight of John , initialised to the intitial_weight provided.
days variable contains the number of days John went to gym.
While loop is executed until the weight of John becomes less than or equal to the target_weight variable.
Code:
def days_for_target(initial_weight, target_weight):
day = 0
weight = initial_weight
days = 0
while(weight>target_weight):
if(day<5):
weight = weight - 10
day = day+1
elif(day==5):
weight = weight + 8
day = day+1
else:
weight = weight + 8
day = 0
days = days + 1
return days