One way to achieve rounding without using the round() function is by manipulating the number to include only the desired number of digits after the decimal point.
# Function to round pi to the specified number of digits
def round_pi_to_precision(digits):
# Calculate pi with extra precision
pi_with_extra_precision = math.pi * (10 ** (digits + 1))
# Truncate the extra precision
truncated_pi = int(pi_with_extra_precision)
# Divide by 10 to shift the decimal point back
rounded_pi = truncated_pi / (10 ** digits)
return rounded_pi
# Get user input for the number of digits
num_digits = int(input("Please enter the number of digits of precision for pi: "))
# Validate input
if num_digits < 0:
print("Please enter a non-negative number.")
else:
# Calculate and print the rounded value of pi
result = round_pi_to_precision(num_digits)
print(f"The value of pi to {num_digits} digits is: {result}")