Skip to content

Commit 660c1dd

Browse files
Merge pull request geekcomputers#1993 from NitkarshChourasia/testing
add: one rep max calculator, weightlifting.
2 parents ba3d171 + 58b7c25 commit 660c1dd

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# One-Rep Max Calculator
2+
3+
This repository contains two Python programs that can calculate the estimated one-repetition maximum (1RM) for a weightlifting exercise. The 1RM is the maximum amount of weight that you can lift for one rep. It is useful for tracking your strength progress and planning your training.
4+
5+
## Command-line version
6+
7+
The file `one_rep_max_calculator.py` is a command-line version of the 1RM calculator. It prompts the user to enter the weight lifted and the number of reps performed, and then calculates and displays the estimated 1RM based on the *Epley formula*.
8+
9+
To run this program, you need Python 3 installed on your system. You can execute the program by typing `python one_rep_max_calculator.py` in your terminal.
10+
11+
## Graphical user interface version
12+
13+
The file `one_rep_max_calculator_gui.py` is a graphical user interface version of the 1RM calculator. It uses Tkinter to create a window with entry fields, labels, and a button. The user can input the weight lifted and the number of reps performed, and then click the calculate button to see the estimated 1RM based on the Epley formula.
14+
15+
To run this program, you need Python 3 and Tkinter installed on your system. You can execute the program by typing `python one_rep_max_calculator_gui.py` in your terminal.
16+
17+
## References
18+
19+
- Epley, B. Poundage chart. In: Boyd Epley Workout. Lincoln, NE: Body Enterprises, 1985. p. 23.
20+
- https://en.wikipedia.org/wiki/One-repetition_maximum
21+
- https://www.topendsports.com/testing/calculators/1repmax.htm
22+
23+
<!-- author: Nitkarsh Chourasia -->
24+
<!-- github_Username: NitkarshChourasia -->
25+
<!-- github_profil_url: https://github.com/NitkarshChourasia -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class OneRepMaxCalculator:
2+
"""
3+
A class to calculate the one-repetition maximum (1RM) for a weightlifting exercise.
4+
"""
5+
6+
def __init__(self):
7+
"""
8+
Initializes the OneRepMaxCalculator with default values.
9+
"""
10+
self.weight_lifted = 0
11+
self.reps_performed = 0
12+
13+
def get_user_input(self):
14+
"""
15+
Prompts the user to enter the weight lifted and the number of reps performed.
16+
"""
17+
self.weight_lifted = int(input("Enter the weight you lifted (in kg): "))
18+
self.reps_performed = int(input("Enter the number of reps you performed: "))
19+
20+
def calculate_one_rep_max(self):
21+
"""
22+
Calculates the one-rep max based on the Epley formula.
23+
"""
24+
return (self.weight_lifted * self.reps_performed * 0.0333) + self.weight_lifted
25+
26+
def display_one_rep_max(self):
27+
"""
28+
Displays the calculated one-rep max.
29+
"""
30+
one_rep_max = self.calculate_one_rep_max()
31+
print(f"Your estimated one-rep max (1RM) is: {one_rep_max} kg")
32+
33+
34+
def main():
35+
"""
36+
The main function that creates an instance of OneRepMaxCalculator and uses it to get user input,
37+
calculate the one-rep max, and display the result.
38+
"""
39+
calculator = OneRepMaxCalculator()
40+
calculator.get_user_input()
41+
calculator.display_one_rep_max()
42+
43+
44+
if __name__ == "__main__":
45+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import tkinter as tk
2+
3+
4+
class OneRepMaxCalculator:
5+
"""
6+
A class used to calculate the estimated one-repetition maximum (1RM) for a weightlifting exercise.
7+
8+
Attributes
9+
----------
10+
window : tk.Tk
11+
The main window of the application.
12+
weight_entry : tk.Entry
13+
Entry field to input the weight lifted.
14+
rep_entry : tk.Entry
15+
Entry field to input the number of reps performed.
16+
result_value_label : tk.Label
17+
Label to display the calculated 1RM.
18+
19+
Methods
20+
-------
21+
calculate_1rm():
22+
Calculates the estimated 1RM based on the Epley formula.
23+
display_result():
24+
Displays the calculated 1RM in the application window.
25+
run():
26+
Runs the application.
27+
"""
28+
29+
def __init__(self):
30+
"""Initializes the OneRepMaxCalculator with a window and widgets."""
31+
self.window = tk.Tk()
32+
self.window.title("One-Rep Max Calculator")
33+
self.window.geometry("300x150")
34+
35+
# Create and pack widgets
36+
tk.Label(self.window, text="Enter the weight you lifted (in kg):").pack()
37+
self.weight_entry = tk.Entry(self.window)
38+
self.weight_entry.pack()
39+
40+
tk.Label(self.window, text="Enter the number of reps you performed:").pack()
41+
self.rep_entry = tk.Entry(self.window)
42+
self.rep_entry.pack()
43+
44+
tk.Button(self.window, text="Calculate", command=self.display_result).pack()
45+
46+
tk.Label(self.window, text="Your estimated one-rep max (1RM):").pack()
47+
self.result_value_label = tk.Label(self.window)
48+
self.result_value_label.pack()
49+
50+
def calculate_1rm(self):
51+
"""Calculates and returns the estimated 1RM."""
52+
weight = int(self.weight_entry.get())
53+
reps = int(self.rep_entry.get())
54+
return (weight * reps * 0.0333) + weight
55+
56+
def display_result(self):
57+
"""Calculates the 1RM and updates result_value_label with it."""
58+
one_rep_max = self.calculate_1rm()
59+
self.result_value_label.config(text=f"{one_rep_max} kg")
60+
61+
def run(self):
62+
"""Runs the Tkinter event loop."""
63+
self.window.mainloop()
64+
65+
66+
# Usage
67+
if __name__ == "__main__":
68+
calculator = OneRepMaxCalculator()
69+
calculator.run()
70+
71+
# Improve the program.
72+
# Make the fonts, bigger.
73+
# - Use text formatting...
74+
# Use dark mode.
75+
# Have an option to use dark mode and light mode.

0 commit comments

Comments
 (0)