(削除) I managed to do this using dictionaries, but I think this could be done in much easier way. (削除ここまで)
Remade it I managed to do this using listsdictionaries, but I think this could be done in much easier way.
i = 0 # count of the repetitions
pushups = {0: 0} # number of pushups at each repetition
sum_of_pushups = {0: 0} # sum of all executed pushups
step = 1
while pushups[i] <= max_pushups + abs(step):
if pushups[i] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
pushups[i] = step + pushups[i - 1]
if pushups[i] < 1: # game stops when you reach 1 push-up
del pushups[i]
break
sum_of_pushups[i] = sum_of_pushups[i - 1] + pushups[i] # counting the sum of all push-ups
del pushups[0]
del sum_of_pushups[0]
return pushups.values(), sum_of_pushups.values()
<hr>
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][0] <= max_pushups + abs(step): # +abs(step) in case step > 1
if pushups[i][0] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
now = step + pushups[i - 1][0]
sum = now + pushups[i - 1][1] # counting the sum of all push-ups by adding previous sum and current pushups
pushups.insert(i, (now, sum))
if pushups[i][0] < 1: # game stops when you reach 0 push-up
break
return pushups[1:-1]
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][0] <= max_pushups + abs(step): # +abs(step) in case step > 1
if pushups[i][0] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
now = step + pushups[i - 1][0]
sum = now + pushups[i - 1][1] # counting the sum of all push-ups by adding previous sum and current pushups
pushups.insert(i, (now, sum))
if pushups[i][0] < 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
(削除) I managed to do this using dictionaries, but I think this could be done in much easier way. (削除ここまで)
Remade it using lists.
i = 0 # count of the repetitions
pushups = {0: 0} # number of pushups at each repetition
sum_of_pushups = {0: 0} # sum of all executed pushups
step = 1
while pushups[i] <= max_pushups + abs(step):
if pushups[i] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
pushups[i] = step + pushups[i - 1]
if pushups[i] < 1: # game stops when you reach 1 push-up
del pushups[i]
break
sum_of_pushups[i] = sum_of_pushups[i - 1] + pushups[i] # counting the sum of all push-ups
del pushups[0]
del sum_of_pushups[0]
return pushups.values(), sum_of_pushups.values()
<hr>
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][0] <= max_pushups + abs(step): # +abs(step) in case step > 1
if pushups[i][0] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
now = step + pushups[i - 1][0]
sum = now + pushups[i - 1][1] # counting the sum of all push-ups by adding previous sum and current pushups
pushups.insert(i, (now, sum))
if pushups[i][0] < 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
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][0] <= max_pushups + abs(step): # +abs(step) in case step > 1
if pushups[i][0] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
now = step + pushups[i - 1][0]
sum = now + pushups[i - 1][1] # counting the sum of all push-ups by adding previous sum and current pushups
pushups.insert(i, (now, sum))
if pushups[i][0] < 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
I managed to do this(削除) I managed to do this using dictionaries, but I think this could be done in much easier way. (削除ここまで)
Remade it using dictionaries, but I think this could be done in much easier waylists.
def leader_step(max):
i = 0
psps = {0: 0}
cnt = {0: 0}
k = 1
while max + abs(k) >= psps[i]:
if psps[i] >= max: # decrease push-ups as they reach max
k = -k
i += 1
psps[i] = k + psps[i-1]
if psps[i] < 1: # game stops when you reach 1 push-up
del psps[i]
break
cnt[i] = cnt[i - 1] + psps[i] # counting the sum of all push-ups
del psps[0]
del cnt[0]
return psps.values(), cnt.values()
i = 0 # count of the repetitions
pushups = {0: 0} # number of pushups at each repetition
sum_of_pushups = {0: 0} # sum of all executed pushups
step = 1
while pushups[i] <= max_pushups + abs(step):
if pushups[i] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
pushups[i] = step + pushups[i - 1]
if pushups[i] < 1: # game stops when you reach 1 push-up
del pushups[i]
break
sum_of_pushups[i] = sum_of_pushups[i - 1] + pushups[i] # counting the sum of all push-ups
del pushups[0]
del sum_of_pushups[0]
return pushups.values(), sum_of_pushups.values()
<hr>
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][0] <= max_pushups + abs(step): # +abs(step) in case step > 1
if pushups[i][0] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
now = step + pushups[i - 1][0]
sum = now + pushups[i - 1][1] # counting the sum of all push-ups by adding previous sum and current pushups
pushups.insert(i, (now, sum))
if pushups[i][0] < 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
I managed to do this using dictionaries, but I think this could be done in much easier way.
def leader_step(max):
i = 0
psps = {0: 0}
cnt = {0: 0}
k = 1
while max + abs(k) >= psps[i]:
if psps[i] >= max: # decrease push-ups as they reach max
k = -k
i += 1
psps[i] = k + psps[i-1]
if psps[i] < 1: # game stops when you reach 1 push-up
del psps[i]
break
cnt[i] = cnt[i - 1] + psps[i] # counting the sum of all push-ups
del psps[0]
del cnt[0]
return psps.values(), cnt.values()
Function should return 2 sequences:
- showing the number of push-ups at each repetition
- showing total sum of push-ups made at each repetition
(削除) I managed to do this using dictionaries, but I think this could be done in much easier way. (削除ここまで)
Remade it using lists.
i = 0 # count of the repetitions
pushups = {0: 0} # number of pushups at each repetition
sum_of_pushups = {0: 0} # sum of all executed pushups
step = 1
while pushups[i] <= max_pushups + abs(step):
if pushups[i] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
pushups[i] = step + pushups[i - 1]
if pushups[i] < 1: # game stops when you reach 1 push-up
del pushups[i]
break
sum_of_pushups[i] = sum_of_pushups[i - 1] + pushups[i] # counting the sum of all push-ups
del pushups[0]
del sum_of_pushups[0]
return pushups.values(), sum_of_pushups.values()
<hr>
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][0] <= max_pushups + abs(step): # +abs(step) in case step > 1
if pushups[i][0] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
now = step + pushups[i - 1][0]
sum = now + pushups[i - 1][1] # counting the sum of all push-ups by adding previous sum and current pushups
pushups.insert(i, (now, sum))
if pushups[i][0] < 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
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, stepmax): # maximum pushups a person can do and a step of increment
i = 0 # count of the repetitions
pushups: List[Tuple[int, int]]psps = [({0,: 0)]}
# number ofcnt pushups= at{0: the0}
beginning (at each repetition,k it= total)1
while pushups[i][0] <= max_pushupsmax + abs(step): # +abs(stepk) in case step >>= 1psps[i]:
if pushups[i][0]psps[i] >= max_pushupsmax: # decrease push-ups as they reach max
stepk = -stepk
i += 1
nowpsps[i] = stepk + pushups[i psps[i- 1][0]1]
sumif =psps[i] now< +1: pushups[i - 1][1] # countinggame thestops sumwhen ofyou allreach 1 push-upsup
by adding previous sum and current pushups del psps[i]
pushups.insert(i, (now, sum)) break
ifcnt[i] pushups[i][0]= <cnt[i 1:- 1] #+ gamepsps[i] stops# whencounting youthe reachsum 0of all push-upups
del psps[0]
del breakcnt[0]
return pushups[1:-1]psps.values(), cnt.values()
Function should return 2 sequences:
- showing the number of push-ups at each repetition
- showing total sum of push-ups made at each repetition
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][0] <= max_pushups + abs(step): # +abs(step) in case step > 1
if pushups[i][0] >= max_pushups: # decrease push-ups as they reach max
step = -step
i += 1
now = step + pushups[i - 1][0]
sum = now + pushups[i - 1][1] # counting the sum of all push-ups by adding previous sum and current pushups
pushups.insert(i, (now, sum))
if pushups[i][0] < 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
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.
def leader_step(max):
i = 0
psps = {0: 0}
cnt = {0: 0}
k = 1
while max + abs(k) >= psps[i]:
if psps[i] >= max: # decrease push-ups as they reach max
k = -k
i += 1
psps[i] = k + psps[i-1]
if psps[i] < 1: # game stops when you reach 1 push-up
del psps[i]
break
cnt[i] = cnt[i - 1] + psps[i] # counting the sum of all push-ups
del psps[0]
del cnt[0]
return psps.values(), cnt.values()
Function should return 2 sequences:
- showing the number of push-ups at each repetition
- showing total sum of push-ups made at each repetition