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
Sending Files to Your Server with Code
This blog post is about how you can use git and vscode to send files from your local environment to...
The 10-second Guide to JSLint (Or, What's the Difference Between ' == ' and ' === '?)
10-second guide to JSLint No semicolons. Use === instead of == . No ++ or -- . Use /*global*/ to...
Code Optimization vs Alternatives: Complete Comparison
Code Optimization vs Alternatives: Complete Comparison In an era where digital systems underpin nearly every aspect of modern life, from...
Coding Town
Coding Town is a new site that aims to help you learn how to code. By providing you with a...
