Advertisement
Edwinlga

gym_workout_tracker.py

Feb 17th, 2025
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | Source Code | 0 0
  1. """
  2. Daily Python Projects
  3. Build a Gym Workout Tracker with Python
  4. Level 1: Beginner
  5. https://dailypythonprojects.substack.com/p/build-a-gym-workout-tracker-with
  6.  
  7.    This program helps you track your workout routines, sets, reps, and weights. It lets you add exercises, record your progress, and review past workouts. Perfect for gym users who want to log their progress.
  8. """
  9.  
  10. workout = {
  11.     'Burpee':[{'session':1, 'sets':3, 'reps':10, 'weight':5},{'session':2, 'sets':3, 'reps':10, 'weight':7}],
  12.     'Leg extension':[{'session':0, 'sets':0, 'reps':0, 'weight':0}]
  13.     }
  14.  
  15. def add_exercise(name):
  16.     name = name.capitalize().strip()
  17.  
  18.     if name not in workout:
  19.         workout[name]=[{'session':0, 'sets':0, 'reps':0, 'weight':0}]
  20.         print (f"Added exercise: {name}")
  21.         return
  22.     else:
  23.         print ("The exercise is registered. Try again.")
  24.         return    
  25.  
  26. def add_log(name: str, sets: int, reps: int, weight: float):
  27.     name = name.capitalize().strip()
  28.     if name in workout:
  29.         if workout[name][0]['session'] == 0:
  30.             workout[name][0] = {'session':1, 'sets':sets, 'reps':reps, 'weight':weight}
  31.         else:
  32.             n_sessions = len(workout[name])
  33.             workout[name].append({'session':n_sessions + 1, 'sets':sets, 'reps':reps, 'weight':weight})
  34.  
  35. def view_progress():
  36.     for exercise, data in workout.items():
  37.         print (f"\nProgress for {exercise}: ")
  38.         for data_session in data:
  39.             print (f"Session {data_session['session']}: {data_session['sets']} sets of {data_session['reps']} reps at {data_session['weight']} kg")          
  40.  
  41. def main():
  42.     choice = 0
  43.     while True:
  44.         print ("\n🦾 Gym Tracker Options:\n")
  45.         print ("1. Add Exercise")
  46.         print ("2. Log Workout")
  47.         print ("3. View Progress")
  48.         print ("4. Exit ")
  49.  
  50.         choice = int(input("Select a option: "))
  51.        
  52.         if choice == 1:
  53.             exercise_name = input ("Enter exercise name: ").capitalize()
  54.             add_exercise(exercise_name)
  55.            
  56.         elif choice == 2:
  57.             exercise_name = input ("Enter exercise name: ")
  58.             sets = int(input ("Enter sets number: "))
  59.             repts = int(input ("Enter repetions number: "))
  60.             weight = float(input ("Enter the lifting weight: "))
  61.            
  62.             add_log(exercise_name, sets, repts, weight)
  63.            
  64.         elif choice == 3:
  65.             view_progress()
  66.            
  67.         elif choice == 4:
  68.             break
  69.  
  70.         else:
  71.             print ("Invalid option. Try again")
  72.            
  73.         follow = input("Do you want to do other operation? (S/N): ").lower()
  74.         if follow == 'n':
  75.             break
  76.  
  77. if __name__ == "__main__":
  78.     main()
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement