<p>请尝试以下简化代码,以帮助您避免将来出现复杂的错误:</p>
<pre><code>import random
exercises = {"chest": ['Bench Press', 'Dumbell Press', 'Chest Press Machine', 'Cable Flies', 'Cable Crossover', 'Decline Bench Press', 'Angled Dips', 'Smith Machine Bench Press', 'Inner Chest Push'],
"shoulders": ['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'],
"back": ['Dumbell Curls ', 'Hammer Curls', 'Preacher Curls', 'Machine Curls', 'Close Grip Chin Ups', 'Close Grip Pulldown', 'Half Rep Curls', 'Rotating Curls', 'Drop Set Curls'],
"triceps": ['Cable Pushdowns', 'Overhead Dumbell Extensions', 'Overhead Barbell Extensions', 'Upright Dips', 'Skullcrushers', 'Close Grip Benchpress', 'Tricep Kickbacks', 'Overhead Rope Extensions', 'Drop Set Pushdowns'],
"biceps": ['Lat Pulldowns', 'Pullups', 'Deadlifts', 'Bent Over Rows', 'Dumbell Rows', 'Rack Pulls', 'Upright Row', 'Low Rows', 'One Arm Cable Pull'],
}
def make_routine(*args, **kwargs):
routine = []
muscle_types = list(kwargs.keys())
for muscle_type in muscle_types:
muscle_exercises = exercises[muscle_type]
exercises_per_day = kwargs[muscle_type]
routine.extend(random.sample(muscle_exercises, exercises_per_day))
return routine
if __name__ == '__main__':
day1_routine = make_routine(chest=4, triceps=2)
day2_routine = make_routine(shoulders=5)
print("day1_routine:", day1_routine)
print("day2_routine:", day2_routine)
# You get the idea
# Just make you specifications as key word arguments in your calling function
#
</code></pre>