回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>首先,我很难理解这个问题,所以很抱歉在解释时出现任何混乱。你知道吗</p>
<p>我目前正在制作一个健身房锻炼程序生成器,它将随机抽取特定数量(由我指定)的锻炼,用于特定的msucle组(也由我指定)。我有一个名为<code>array</code>的数组,如下所示</p>
<pre><code>[['Bench Press', 'Dumbell Press', 'Chest Press Machine', 'Cable Flies', 'Cable Crossover', 'Decline Bench Press', 'Angled Dips', 'Smith Machine Bench Press', 'Inner Chest Push'],
['Incline Bench Press', 'Incline Dumbell Press', 'Incline Cable Flies', 'Incline Chest Press Machine', 'Incline Dumbell Flies', 'Raised Pushups', 'Smith Machine Incline Bench Press', 'Rotating Incline Dumbell Press', 'Inner Check Upwards Barbell Push'],
['Barbell Overhead Press', 'Dumbell Overhead Press', 'Dumbell Lateral Raise', 'Face Pulls', 'Dumbell Front Raise', 'Reverse Flies', 'Smith Shoulder Press', 'Cable Side Raise', 'Behind Head Overhead Press'],
['Dumbell Curls ', 'Hammer Curls', 'Preacher Curls', 'Machine Curls', 'Close Grip Chin Ups', 'Close Grip Pulldown', 'Half Rep Curls', 'Rotating Curls', 'Drop Set Curls'],
['Cable Pushdowns', 'Overhead Dumbell Extensions', 'Overhead Barbell Extensions', 'Upright Dips', 'Skullcrushers', 'Close Grip Benchpress', 'Tricep Kickbacks', 'Overhead Rope Extensions', 'Drop Set Pushdowns'],
['Lat Pulldowns', 'Pullups', 'Deadlifts', 'Bent Over Rows', 'Dumbell Rows', 'Rack Pulls', 'Upright Row', 'Low Rows', 'One Arm Cable Pull'],
['Squats', 'Leg Press', 'Calf Raisers', 'Leg Extensions', 'Leg Curls', 'Lunges', 'Rear Kicks', 'Abductor', 'Adductor']]
</code></pre>
<p>使用2d阵列的每个阵列都包含针对不同肌肉群的练习。你知道吗</p>
<p>现在我创建的程序是4天的程序。第一天,生成胸部和三头肌(数组1和数组5)。第二天是肩膀(阵法3)。第3天是背部和二头肌(阵法4和6),最后第4天是腿部(阵法6)。你知道吗</p>
<p>应使用以下功能设置此系统:</p>
<pre><code>def FourDays():
global Day1
Day1 = [4,0,0,0,2,0,0]
global Day2
Day2 = [0,0,5,0,0,0,0]
global Day3
Day3 = [0,0,0,2,0,4,0]
global Day4
Day4 = [0,0,0,0,0,0,5]
Day1_routine = Routine_Maker3(array, Day1)
Day2_routine = Routine_Maker3(array, Day2)
Day3_routine = Routine_Maker3(array, Day3)
Day4_routine = Routine_Maker3(array, Day4)
</code></pre>
<p>例如-<code>Day2</code>(也就是肩部),在数组的第三个索引中有数字5。这意味着第三个阵法有5个练习,这个阵法包含肩部练习。你知道吗</p>
<p>这些变量(<code>Day1</code>、<code>Day2</code>、<code>Day3</code>和<code>Day4</code>)然后被传递给下面的函数,该函数负责从<code>array</code>获得适当的练习量</p>
<pre><code>def Routine_Maker3(array, exercises_per_day):
old_routine = []
pos = 0
for i in range(7):
if pos >= len(array):
pos = 0
temporal_array = [array[pos][j] for j in random.sample(range(9), exercises_per_day[pos])]
old_routine.append(temporal_array)
pos += 1
print (old_routine)
new_routine=[]
for e in old_routine:
new_routine += e
print (new_routine)
</code></pre>
<p>请注意:<code>Day1</code>、<code>2</code>、<code>3</code>和<code>4</code>应作为<code>exercises_per_day</code>传递</p>
<p>下面是它应该输出的示例:</p>
<pre><code>['Cable Crossover', 'Cable Flies', 'Smith Machine Bench Press', 'Inner Chest Push', 'Upright Dips', 'Overhead Dumbell Extensions']
['Behind Head Overhead Press', 'Dumbell Overhead Press', 'Smith Shoulder Press', 'Face Pulls', 'Dumbell Lateral Raise']
['Machine Curls', 'Close Grip Pulldown', 'Lat Pulldowns', 'One Arm Cable Pull', 'Pullups', 'Upright Row']
['Abductor', 'Rear Kicks', 'Lunges', 'Leg Curls', 'Squats']
</code></pre>
<p>我得到的错误是列表索引超出了范围,它说这两行有问题:</p>
<pre><code>Day1_routine = Routine_Maker4(array, Day1)
temporal_array = [array[pos][j] for j in random.sample(range(9), exercises_per_day[pos])]
</code></pre>