async def main():
task1 = asyncio.create_task(factorial(“A”, 2))
task2 = asyncio.create_task(factorial(“B”, 1))
await task1
await task2
try:
asyncio.run(main())
except Exception as e:
print(f”Caught error: {e!r}”)
import math
def factorial(n):
if n == 0:
return 1
else:
recurse = factorial(n-1)
result = n * recurse
return result
print factorial(4)
def factorial(number):
if number == 0:
return 1
return number * factorial(number – 1)
def factorial(n):
if n == 1:
return n
else:
return n * factorial(n-1)
n = int(input(“Enter number:”))
print(“Factorial:”)
print(factorial(n))
def factorial(n=None):
if n is None:
return None
elif not isinstance(n, int) or n < 0:
raise ValueError('n must be a positive integer')
elif n == 0:
return 1
else:
return n * factorial(n - 1)
factorial(5)
def factorial(n):
"""Returns the factorial of a number."""
if n < 0:
raise ValueError("Inputs 0 or greater only")
elif not isinstance(n, int):
raise TypeError("Invalid type: {}".format(type(n)))
elif n == 100:
raise FactorialError("Value too high")
result = 1
for i in range(1, n + 1):
result *= i
return result
def fact(n):
if n == 0:
return 1
else:
return n * fact(n-1)
print(fact(3))
Tomy is a contributor at AskMeCode. We are committed to providing well-researched, accurate, and valuable content to our readers.
You May Also Like
Is CodeHub missing a feature that you would like to see? Please take the time to fill out this form here.
Is CodeHub missing a feature that you would like to see? Here is your chance to make suggestions about what...
Why You Should Practice Your Python Programs
Why You Should Practice Your Python Programs: a tutorial blog to teach people the importance of practicing their python programs....
The Ultimate Collection of Code 1 Software Downloads
The Ultimate Collection of Code 1 Software Downloads: A company website that hosts various code 1 software. Code 1 is...
Canva Code: Empowering Non-Technical Users to Create Interactive Digital Experiences
Breaking Down Barriers to Coding Breaking Down Barriers to Coding Canva Code has introduced a new feature that makes coding...
