I wanted to create a function describing a sport game called "Leader". The idea is that you make as many push-ups as you can, increasing each repetition by 1 and as you reach your maximum, each next repetition is decreased by 1 until you reach 0 push-ups eventually.
I managed to do this using dictionaries, but I think this could be done in much easier way.
from typing import List, Tuple def leader_step(max_pushups, step): # maximum pushups a person can do and a step of increment i = 0 # count of the repetitions pushups: List[Tuple[int, int]] = [(0, 0)] # number of pushups at the beginning (at each repetition, it total) while pushups[i] <= max_pushups + abs(step): # +abs(step) in case step > 1 if pushups[i] >= max_pushups: # decrease push-ups as they reach max step = -step i += 1 now = step + pushups[i - 1] sum = now + pushups[i - 1] # counting the sum of all push-ups by adding previous sum and current pushups pushups.insert(i, (now, sum)) if pushups[i] < 1: # game stops when you reach 0 push-up break return pushups[1:-1]
Function should return 2 sequences:
- showing the number of push-ups at each repetition
- showing total sum of push-ups made at each repetition