-1

I am trying to make a Workout Routine Generator in Python. I have made lists of exercises for each muscle group to work out. I am having trouble making different exercise lists that pull a random exercise from the muscle group lists. The exercise lists I have paired with specific days of the week. Also need help with getting rid of the last comma that separates each printed exercise.

#Muscle Group Exercises

Chest= ["Barbell Bench Press", "Flat Bench Dumbbell Press", "Pushups", "Machine Decline Press", "Seated Machine Chest Press", "Incline Dumbbell Press", "Chest Dips", "Incline Bench Cable Fly", "Incline Dumbell Pull-Over", "Pec-Deck Machine"]
Back= ["Barbell Deadlift", "Bent-Over Barbell Deadlift", "Wide-Grip Pull-Up", "Standing T-Bar Row", "Wide-Grip Seated Cable Row", "Reverse-Grip Smith Machine Row", "Close-Grip Pull-Down", "Single-Arm Dumbbell Row", "Decline Bench Dumbbell Pull-Over", "Single-Arm Smith Machine Row"]
Shoulders= ["Barbell Push Press", "Standing Military Press", "Dumbbell Incline Row", "Seated Overhead Dumbbell Press", "Seated Overhead Barbell Press", "Upright Row", "Arnold Press", "Machine Rear-Delt Fly", "Dumbbell Lateral Raise", "Front Dumbbell Raise"]
Legs= ["Squat", "Leg Curl", "Olympic Lift: Snatch and Power Clean", "Leg Extension", "Bulgarian Split Squat", "Hack Squat", "Dumbbell Lunge", "Leg Press", "Romanian Deadlift", "Machine Squat"]
Biceps= ["Standing Dumbbell Curl", "Hammer Curl", "Incline Dumbbell Curl", "Zottman Curl", "Barbell Bent-over Row", "Chin-up", "Regular EZ Bar Curl", "Underhand Seated Row", "Preacher Curl"]
Triceps= ["Close-grip Bench Press", "Rope Tricep Pushdown", "Tricep Dips", "Overhead Triceps Extension", "Skullcrushers", "Diamond Pushups", "Tricep Kickback", "Dumbbell Press", "Pushups", "One Arm Kettlebell Press"]
Aerobic= ["mile run", "jumping jacks", "sprints", "burpees", "cycling"]

#How I tried to pull randomly from lists

import random
a = Chest[random.randint(0, len(Chest)-1)]
b = Back[random.randint(0, len(Back)-1)]
c = Shoulders[random.randint(0, len(Shoulders)-1)]
d = Legs[random.randint(0, len(Legs)-1)]
e = Biceps[random.randint(0, len(Biceps)-1)]
f = Triceps[random.randint(0, len(Triceps)-1)]
g = Aerobic[random.randint(0, len(Aerobic)-1)]

exercise1= ["a", "b", "c", "d", "e", "f"]
exercise2= ["d", "f", "e", "a", "b", "c"]
exercise3= ["c", "b", "a", "d", "f", "e"]
exercise4= ["g"]
Rest= ["Recovery Day"]

#Workout Routine Organizer

w = [['Monday:',exercise1], ['Tuesday:',Rest], ['Wednesday:',exercise2], ['Thursday:',Rest], ['Friday:',exercise3], ['Saturday:',exercise4], ['Sunday:',Rest]]

y=0
for list in w:
    print(w[y][0])
    for x in w[y][1]:
        print (x, end= ", ")
    print("\n")
    y+=1
cs-mike
  • 3
  • 1
  • Possible duplicate of [How to randomly select an item from a list?](https://stackoverflow.com/questions/306400/how-to-randomly-select-an-item-from-a-list) – Valentino May 01 '19 at 19:38
  • Can you explain exactly what your code does differently than you want? – Blorgbeard May 01 '19 at 19:38

2 Answers2

0

It looks to me like you may have meant something like:

exercise1 = [a, b, c, d, e, f]
exercise2 = [d, f, e, a, b, c]
exercise3 = [c, b, a, d, f, e]
exercise4 = [g]

The code as you have it is adding a list of strings to exercise 1 through 5, not the actual list you have stored in those variables.

Jamie Counsell
  • 7,730
  • 6
  • 46
  • 81
0

Some errors and suggestions to your code

  1. You can use random.choice to select an random element from the list
  2. I think in exercise1, exercise2... variable, you meant to do [a, b, c, d, e, f] etc
  3. You can create a string out of w[y][1] and print it to get rid of last comma
Chest= ["Barbell Bench Press", "Flat Bench Dumbbell Press", "Pushups", "Machine Decline Press", "Seated Machine Chest Press", "Incline Dumbbell Press", "Chest Dips", "Incline Bench Cable Fly", "Incline Dumbell Pull-Over", "Pec-Deck Machine"]
Back= ["Barbell Deadlift", "Bent-Over Barbell Deadlift", "Wide-Grip Pull-Up", "Standing T-Bar Row", "Wide-Grip Seated Cable Row", "Reverse-Grip Smith Machine Row", "Close-Grip Pull-Down", "Single-Arm Dumbbell Row", "Decline Bench Dumbbell Pull-Over", "Single-Arm Smith Machine Row"]
Shoulders= ["Barbell Push Press", "Standing Military Press", "Dumbbell Incline Row", "Seated Overhead Dumbbell Press", "Seated Overhead Barbell Press", "Upright Row", "Arnold Press", "Machine Rear-Delt Fly", "Dumbbell Lateral Raise", "Front Dumbbell Raise"]
Legs= ["Squat", "Leg Curl", "Olympic Lift: Snatch and Power Clean", "Leg Extension", "Bulgarian Split Squat", "Hack Squat", "Dumbbell Lunge", "Leg Press", "Romanian Deadlift", "Machine Squat"]
Biceps= ["Standing Dumbbell Curl", "Hammer Curl", "Incline Dumbbell Curl", "Zottman Curl", "Barbell Bent-over Row", "Chin-up", "Regular EZ Bar Curl", "Underhand Seated Row", "Preacher Curl"]
Triceps= ["Close-grip Bench Press", "Rope Tricep Pushdown", "Tricep Dips", "Overhead Triceps Extension", "Skullcrushers", "Diamond Pushups", "Tricep Kickback", "Dumbbell Press", "Pushups", "One Arm Kettlebell Press"]
Aerobic= ["mile run", "jumping jacks", "sprints", "burpees", "cycling"]

#How I tried to pull randomly from lists

import random

#Choose random exercises from all lists
a = random.choice(Chest)
b = random.choice(Back)
c = random.choice(Shoulders)
d = random.choice(Legs)
e = random.choice(Biceps)
f = random.choice(Triceps)
g = random.choice(Aerobic)

exercise1= [a, b, c, d, e, f]
exercise2= [d, f, e, a, b, c]
exercise3= [c, b, a, d, f, e]
exercise4= [g]
Rest= ["Recovery Day"]

#Workout Routine Organizer
w = [['Monday:',exercise1], ['Tuesday:',Rest], ['Wednesday:',exercise2], ['Thursday:',Rest], ['Friday:',exercise3], ['Saturday:',exercise4], ['Sunday:',Rest]]

y=0
for list in w:
    print(w[y][0])
    #Join whole list w[y][1] as a string, then print it
    print(", ".join(w[y][1]))
    print("\n")
    y+=1

The output will be

Monday:
Incline Dumbbell Press, Single-Arm Smith Machine Row, Seated Overhead Barbell Press, Hack Squat, Preacher Curl, Skullcrushers


Tuesday:
Recovery Day


Wednesday:
Hack Squat, Skullcrushers, Preacher Curl, Incline Dumbbell Press, Single-Arm Smith Machine Row, Seated Overhead Barbell Press


Thursday:
Recovery Day


Friday:
Seated Overhead Barbell Press, Single-Arm Smith Machine Row, Incline Dumbbell Press, Hack Squat, Skullcrushers, Preacher Curl


Saturday:
jumping jacks


Sunday:
Recovery Day



Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40