Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Calculator/Quadratic_Equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def factorize_quadratic(a, b, c):
plt.ylabel("y")

# Set the title
plt.title("Quadratic Equation: y = {}x^2 + {}x + {}".format(a, b, c))
plt.title(f"Quadratic Equation: y = {a}x^2 + {b}x + {c}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 137-137 refactored with the following changes:


# Set y-axis at the center
plt.axhline(0, color="black", linewidth=0.5)
Expand Down
13 changes: 6 additions & 7 deletions Calculator/bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate_bmi refactored with the following changes:



def get_bmi_category(bmi):
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:


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)
Expand Down
28 changes: 6 additions & 22 deletions Calculator/mega_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate_factors refactored with the following changes:



factors_x = calculate_factors(x)
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_prime refactored with the following changes:



def is_composite(number):
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_coprime_numbers refactored with the following changes:



def print_coprimes(co_primes, variable):
if max(co_primes) >= 100:
print(f"The entered number for {variable} is greater than 100.")
pass
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function print_coprimes refactored with the following changes:

else:
print(f"The coprime numbers for {variable} are:")
print(co_primes)
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 469-507 refactored with the following changes:

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")
Expand All @@ -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): ")
Expand All @@ -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):
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function differentiate_equation refactored with the following changes:


def integrate_equation(equation, var, lower, upper):
integrated_equation = sympy.integrate(equation, var)
Expand Down
9 changes: 3 additions & 6 deletions Calculator/special_relativity_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function time_dilation refactored with the following changes:



# 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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function length_contraction refactored with the following changes:



# 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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function energy refactored with the following changes:



if __name__ == "__main__":
Expand Down