dimanche 17 juillet 2022

How to choose randomly from a list, inside a dictionary

I have been trying to make a "Workout Generator" that uses my input to give me a gym workout that focuses on specific muscles or body parts depending on my choice ("input").

I am stuck because I am now trying to get a random workout from a list (Which is a dictionary value) while being in a randomly chosen key inside a dictionary.

This is my first solo project and nothing i have tried has been working so far and I really want to be able to complete this :)

Here is the code so far, I have put the line of code that accepts input as a note so that when i run to test i dont have to keep inputing the same thing, and also made a note the second line of code in my if statement because if I fix this problem with the first one then I can repeat the same for the second one.

Here is a sample of the code

import random
choose_workout = input("Enter body area here: ")


upper_body_cb = {
"chest" : ["Bench press" , "Pushups"],
"back" : ["Lateral Pulldown" , "Pull Up"]
}
random_upper_cb = print(random.choice(list(upper_body_cb.values())))

if choose_workout == "upper c":
    print(random_upper_cb)



Aucun commentaire:

Enregistrer un commentaire