+ 6
Need some help for assignment today
How to calculate the Factorial: Sample output: 0! = 1 1! = 1 2! = 1 3! = 1 . . n! = 1 * 2 * 2 * 3 * 2 * 3 * ... n-1 * n Please enter a number: 5 5! = 120 My attempt: # Write your code def factoRecurs(numb): if numb ==1: return 1 else: print(numb) return numb * factorRecurs(numb-1) inpNum = int (input(“Enter a number”)) if inpNum >= 1: print(“the factorial ”)
47 Réponses
+ 14
You can use a loop, a recursive function and a few other ways.
Try to figure out your own solution, only practice makes you a programmer.
If you can't get it to run, you can link your attempt here, we'll try to help you with a hint instead of the answer.
+ 8
A simple way is also to use a for loop with a range object.
+ 3
Try this code...
print((lambda x: 1 if x==0 else __import__('functools').reduce(lambda a,b:a*b, [i for i in range(1, x+1)])) (int(input())))
+ 3
use a for loop with a range object
+ 1
i will try my best
+ 1
i will thanks
+ 1
Try this one.....
def fact(x):
a=1
for i in range (1,x):
a*=i
print('Factorial of',num,'is',a)
num=int(input('Enter a number:'))
if num==0:
print('Factorial of',num,'is 1')
elif num>0:
fact(num+1)
else:
print('Invalid Entry')
+ 1
https://code.sololearn.com/clx3S2dXACID/?ref=app
You can have a look at this
+ 1
n=int(input())
f=1
if (n==0):
print("1")
elif(n>0):
while(n!=0):
f=f*n
n-=1
print(f)
0
Your samples.are you sure, they are correct?
0
yeah i copy it from the assignment
0
this is the question
Write a function that accepts n as a parameter and calculate its factorial (n!) and return
its result.
0
Frankly, I can not find a solution
0
and i need to solve it to pass
0
# Write your code
def factoRecurs(numb):
if numb ==1:
return 1
else:
print(numb)
return numb * factorRecurs(numb-1)
inpNum = int (input(“Enter a number”))
if inpNum >= 1:
print(“the factorial ”)
0
can you try it and find the problem
0
thanks so much but this solotion its okay with the rols in the question?
0
not like this but my teacher are so intense with code he didnt accept any
is my code okay with his rols?
0
so i will get the full mark?
i wish it