0

I recently started teaching myself python with YouTube videos and a couple of books. I decided to try my hand at a simple program to help with randomizing my workouts, but it isn't running as expected. I'm using Python 3. The code seems to run but not the if statements as it is printing the number the user inputs. I would love any guidance possible; recently relocated and I have no one to lend an extra set of eyes. (I don't have a rubber duck, but I tried explaining it to my squirtle Garcia; no help) Thanks!

#set exercises equal to choices
push_ups = [1,7,13,19,25,31,37,43,49,55,61,67,73,79,85,91,97]
sit_ups = [2,8,14,20,26,32,38,44,50,56,62,68,74,80,86,92,98]
burpees = [3,9,15,21,27,33,39,45,51,57,63,69,75,81,87,93,99]
stretches = [4,10,16,22,28,34,40,46,52,58,64,70,76,82,88,94,100]
run_in_place =[5,11,17,23,29,35,41,47,53,59,65,71,77,83,89,95]
squats = [6,12,18,24,30,36,42,48,54,60,66,72,78,84,90,96]

#greet user
#ask user for input to determine which workout
print("Welcome to your workout buddy!")
print("To make a workout, pick exercises with random numbers until your workout time is 
finished.")
choice = input("Please type a number between 1 and 100 to choose an exercise: ")

if choice in push_ups:
    print("Do 10 Push Ups")

    if choice in sit_ups:
        print("Do 10 Sit Ups")
  
        if choice in burpees:
            print("Do 10 Burpees")
      
            if choice in stretches:
                print("Stretch for 1 minute")
            
                if choice in run_in_place:
                    print("Run in place for 1 minute")

                    if choice in squats:
                        print("Do 10 Squats")

print(choice)
  • 3
    Above and beyond the failure to convert between `str` and `int`: You realize that you're only evaluating whether `if choice in sit_ups:` is true when `if choice in push_ups:` is _also_ true? You probably (rather: certainly) don't want to be nesting your indentation. – Charles Duffy Jan 03 '22 at 02:19
  • ^ Assuming it does evaluate as True – OneCricketeer Jan 03 '22 at 02:20
  • By the way, you can shorten those manual lists with something like `range(1, 101, 6)` – OneCricketeer Jan 03 '22 at 02:23
  • Since the lists are of numbers that all correspond to a particular value mod 6, you can shorten it much further -- try `print(["Do 10 Squats", "Do 10 Push Ups", "Do 10 Sit Ups", "Do 10 Burpees", "Stretch for 1 minute", "Run in place for 1 minute"][int(input("Please type a number to choose an exercise: ")) % 6])` – Samwise Jan 03 '22 at 02:25
  • Thank you! I only started learning a couple of days ago, so I really appreciate the help. It's working now, but I'm definitely going to try and streamline it with your tips. And make it repeat until the user is done. I just have to get that far in the books and videos for it to make sense. – Certifiable Scribe Jan 03 '22 at 02:26
  • Even better, use true (pseudo)randomness, human chosen numbers are never random. ```import random ; print(random.choice(["Do 10 Squats", "Do 10 Push Ups", "Do 10 Sit Ups", "Do 10 Burpees", "Stretch for 1 minute", "Run in place for 1 minute"]))``` – mozway Jan 03 '22 at 02:36

0 Answers0