python unit 4 creat a factorial and creat a you own factorial function

When we want to creat a factoral ,the for loops can do you a favor.Now let`s do it.

a=int(input("whatever numbers do you want to calculate")) ? or ?a= eval( input()) ?

b=1

for i in range(a):

b=b*(i+1)

print(b)

#####Notice: the most important is 1*2*3*4*******a ? so easy?

And if you want to use this factorial for more than one time and you donn`t want to repeat this program again again ,then you can define your own function,just like the function inside the python. ?

def factorial(numbers):

x=1

for i in range(numbers):

x=x*(i+1)

return(x)

#$$Then you can use your own function now

y=eval(input()) ? ?or y=int(input()) ?

z=factorial(y)

print(z)


or use 6*5*4*3*2*1

# define a factoral function

def factorial(numbers):

? ? if numbers<=1:

? ? ? return 1

? ? else:

? ? ? ? return numbers*factorial(numbers-1)

y=eval(input())

z=factorial(y)

print(z)



Then i want to do this analysing in resusive program :

The following:


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容