Changed print to f-string

Also printed out results in a math notation
This commit is contained in:
avivfaraj 2021-09-04 10:19:15 -04:00 committed by GitHub
parent a56525855c
commit 4951686999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,11 +64,12 @@ if __name__ == "__main__":
raise ValueError
# Ensure print an error message
except ValueError:
print("Invalid input: Must be an integer or an half-integer!")
print("Error: Input must be an integer or an half-integer!")
number = False
finally:
# Ensure input is a valid number
if number:
print(f"\u0393({num}) = ", end="")
# Ensure input is an integer
if (isinstance(gamma(num), int)):
# Print result
@ -76,7 +77,7 @@ if __name__ == "__main__":
# Otherwise print results with √π (gamma of 0.5 is √π)
# Therefore all results will be a number times √π
else:
results = "{result:.4f}".format(result=gamma(num) / sqrt(pi))
results = f"{gamma(num) / sqrt(pi):.4f}"
results = results.rstrip('0').rstrip('.')
if results == "1":
results = ""