mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Changed print to f-string
Also printed out results in a math notation
This commit is contained in:
parent
a56525855c
commit
4951686999
@ -64,11 +64,12 @@ if __name__ == "__main__":
|
|||||||
raise ValueError
|
raise ValueError
|
||||||
# Ensure print an error message
|
# Ensure print an error message
|
||||||
except ValueError:
|
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
|
number = False
|
||||||
finally:
|
finally:
|
||||||
# Ensure input is a valid number
|
# Ensure input is a valid number
|
||||||
if number:
|
if number:
|
||||||
|
print(f"\u0393({num}) = ", end="")
|
||||||
# Ensure input is an integer
|
# Ensure input is an integer
|
||||||
if (isinstance(gamma(num), int)):
|
if (isinstance(gamma(num), int)):
|
||||||
# Print result
|
# Print result
|
||||||
@ -76,7 +77,7 @@ if __name__ == "__main__":
|
|||||||
# Otherwise print results with √π (gamma of 0.5 is √π)
|
# Otherwise print results with √π (gamma of 0.5 is √π)
|
||||||
# Therefore all results will be a number times √π
|
# Therefore all results will be a number times √π
|
||||||
else:
|
else:
|
||||||
results = "{result:.4f}".format(result=gamma(num) / sqrt(pi))
|
results = f"{gamma(num) / sqrt(pi):.4f}"
|
||||||
results = results.rstrip('0').rstrip('.')
|
results = results.rstrip('0').rstrip('.')
|
||||||
if results == "1":
|
if results == "1":
|
||||||
results = ""
|
results = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user