Answer:
Following are the code to the given question:
def fact(k):#defining a method fact that holds a parameter
o=1#defining a variable o that holds a value that is 1
if(k==0):#defining if block that checks k equal to 0
o=1#using o variable that holds a value 1
else:#defining else block
for i in range(k):#defining for loop to calculates Factorial
o=o*(i+1)#calculating Factorial value
return(o)#return Factorial value
k=10#defining a variable k that holds a value 10
print("Factorial value:", fact(k))#use print method tom print Factorial value
Output:
Factorial value: 3628800
Step-by-step explanation:
- In this code, a method, "fact" is declared that accepts one parameter "k", in the method if block is used, in the if the block it checks k-value that is equal to 0 if the condition is true it will return a value that is "1".
- Otherwise, it will go to the else block. This section, uses the for loop to calculates its factorial value and adds its value into the "o", and returns its value.
- Outside the method, k is declared that holds its value and passes into the fact method parameter, and uses the print method to print its return value.