本文介绍了我在 python 中的阶乘代码有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码用于在 python 中计算数字的阶乘.但我不明白为什么我得到的答案是 1.有人可以纠正我的代码.我想在不使用递归的情况下计算阶乘.
I have the following code for calculating the factorial of a number in python. but I couldnt understand why I am getting the answer as 1. can some one correct my code. I want to calculate the factorial without using recursion.
def factorial (n): result =1 num = n while n<1: result = result * num num = num -1 return result factorial(5) 1 推荐答案 while n < 1:应该是
while num > 1:更多推荐
我在 python 中的阶乘代码有什么问题
发布评论