-
-
Notifications
You must be signed in to change notification settings - Fork 20
copy of main branch (Sourcery refactored) #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,7 @@ def calculate_bmi(weight, height): | |
| Calculates the Body Mass Index (BMI) based on weight and height. | ||
| Returns the calculated BMI value. | ||
| """ | ||
| bmi = weight / (height ** 2) | ||
| return bmi | ||
| return weight / (height ** 2) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def get_bmi_category(bmi): | ||
|
|
@@ -48,26 +47,26 @@ def main(): | |
| print("--------------------") | ||
|
|
||
| weight_unit = input("Enter weight unit (lbs or kgs): ") | ||
| weight = float(input("Enter your weight in {}: ".format(weight_unit))) | ||
| weight = float(input(f"Enter your weight in {weight_unit}: ")) | ||
|
|
||
| height_unit = input("Enter height unit (feet or meters): ") | ||
| height = float(input("Enter your height in {}: ".format(height_unit))) | ||
| height = float(input(f"Enter your height in {height_unit}: ")) | ||
|
|
||
| # Convert weight to kg if entered in lbs | ||
| if weight_unit.lower() == "lbs": | ||
| weight = weight * 0.453592 | ||
| weight *= 0.453592 | ||
|
|
||
| # Convert height to meters if entered in feet | ||
| if height_unit.lower() == "feet": | ||
| height = height * 0.3048 | ||
| height *= 0.3048 | ||
|
Comment on lines
-51
to
+61
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| bmi = calculate_bmi(weight, height) | ||
| category = get_bmi_category(bmi) | ||
|
|
||
| print("\nResults") | ||
| print("--------------------") | ||
| print("BMI: {:.2f}".format(bmi)) | ||
| print("Category: {}".format(category)) | ||
| print(f"Category: {category}") | ||
|
|
||
| weight_range = get_weight_range(height) | ||
| height_range = get_height_range(weight) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,11 +245,7 @@ def get_positive_integer(prompt): | |
|
|
||
|
|
||
| def calculate_factors(number): | ||
| factors = [] | ||
| for i in range(1, number + 1): | ||
| if number % i == 0: | ||
| factors.append(i) | ||
| return factors | ||
| return [i for i in range(1, number + 1) if number % i == 0] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| factors_x = calculate_factors(x) | ||
|
|
@@ -289,10 +285,7 @@ def is_even(number): | |
| def is_prime(number): | ||
| if number < 2: | ||
| return False | ||
| for i in range(2, int(number ** 0.5) + 1): | ||
| if number % i == 0: | ||
| return False | ||
| return True | ||
| return all(number % i != 0 for i in range(2, int(number ** 0.5) + 1)) | ||
|
Comment on lines
-292
to
+288
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def is_composite(number): | ||
|
|
@@ -337,17 +330,12 @@ def gcd(a, b): | |
|
|
||
|
|
||
| def get_coprime_numbers(num): | ||
| coprimes = [] | ||
| for i in range(1, num): | ||
| if gcd(num, i) == 1: | ||
| coprimes.append(i) | ||
| return coprimes | ||
| return [i for i in range(1, num) if gcd(num, i) == 1] | ||
|
Comment on lines
-340
to
+333
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def print_coprimes(co_primes, variable): | ||
| if max(co_primes) >= 100: | ||
| print(f"The entered number for {variable} is greater than 100.") | ||
| pass | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| else: | ||
| print(f"The coprime numbers for {variable} are:") | ||
| print(co_primes) | ||
|
|
@@ -466,9 +454,6 @@ def calculate_hcf(x, y, z): | |
| z = int(input("Enter your third number: ")) | ||
| h = int(input("Enter the number in degree:")) | ||
|
|
||
| else: | ||
| pass | ||
|
|
||
|
Comment on lines
-469
to
-471
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| try: | ||
| print(round(math.asin(h), 3), ", the answer of arcsin in radians") | ||
| print(round(math.acos(h), 3), ", the answer of arccos in radians") | ||
|
|
@@ -493,7 +478,7 @@ def calculate_hcf(x, y, z): | |
| except ValueError: | ||
| print("Please enter a valid option.") | ||
|
|
||
| if g.lower() == "graph" or g.lower() == "both": | ||
| if g.lower() in ["graph", "both"]: | ||
| equation = input("Enter an equation using 'x' variable for graph: ") | ||
| try: | ||
| x_values = input("Enter x-values (comma-separated): ") | ||
|
|
@@ -504,7 +489,7 @@ def calculate_hcf(x, y, z): | |
| plt.plot(x_values, y_values, color="red") | ||
| plt.xlabel("X-axis") | ||
| plt.ylabel("Y-axis") | ||
| plt.title("Graph of " + equation) | ||
| plt.title(f"Graph of {equation}") | ||
| plt.scatter(x_values, y_values, color="red") | ||
| plt.show() | ||
| except (SyntaxError, NameError, TypeError, ZeroDivisionError): | ||
|
|
@@ -537,8 +522,7 @@ def calculate_hcf(x, y, z): | |
|
|
||
| def differentiate_equation(equation, x): | ||
| x = sympy.Symbol("x") | ||
| derivative_equation = sympy.diff(equation, x) | ||
| return derivative_equation | ||
| return sympy.diff(equation, x) | ||
|
Comment on lines
-540
to
+525
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def integrate_equation(equation, var, lower, upper): | ||
| integrated_equation = sympy.integrate(equation, var) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,22 +2,19 @@ | |
| # Function to calculate time dilation | ||
| def time_dilation(time, velocity): | ||
| gamma = 1 / (1 - (velocity ** 2 / 299792458 ** 2)) # Lorentz factor | ||
| time_dilated = time * gamma | ||
| return time_dilated | ||
| return time * gamma | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| # Function to calculate length contraction | ||
| def length_contraction(length, velocity): | ||
| gamma = 1 / (1 - (velocity ** 2 / 299792458 ** 2)) # Lorentz factor | ||
| length_contracted = length / gamma | ||
| return length_contracted | ||
| return length / gamma | ||
|
Comment on lines
-12
to
+11
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| # Function to calculate energy using E=mc^2 | ||
| def energy(mass): | ||
| c = 299792458 # Speed of light in m/s | ||
| energy = mass * c ** 2 | ||
| return energy | ||
| return mass * c ** 2 | ||
|
Comment on lines
-19
to
+17
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
137-137refactored with the following changes:use-fstring-for-formatting)