python - How do I print out one factorial number? My code keeps printing out too many numbers and I do not know why?
问题描述
#Python Printing out Factorial number
#Input ask for a number
iMax = int(input("What is the number to factorialize: "))
iFactorial = 1
iCount = 1
While loop
while iCount <= iMax:
iFactorial = iFactorial * iCount
iCount = iCount + 1
Print Factorial
print("factorial of ", iMax, " is ", iFactorial)
解决方案
Here you have a better way to compute factorial:
num = int(input())
fac = 1
for i in range(1, num + 1):
fac *= i
print("The factorial of", num, "is", fac)
推荐阅读
- kubernetes - Connect ResourceManager for Flink FLIP-6 开始新的“会话作业”
- c# - .NET MVC 获取具有任何角色列表的所有用户
- java - 使用 JPA 持久化一个时间集合
- sql-server - SQL Server 中的 OLE DB 提供程序问题?
- react-table - 反应表格式空日期
- angular - Angular7:如何防止通过 URL 导航?
- ansible - 在 delegate_to 语句中循环包含 Ansible 主机组的变量
- python - 在 python 中需要帮助删除 json 列表中的字典
- c# - 编辑用于生成方法的代码片段?
- vb.net - WinAppDriver - 无法在组合框中单击项目或选择项目