我是Python 新手,目前正在阅读Python 3的绝对初学者和面对以下问题.
我想用程序计算阶乘.
而代码是这样的:
N = input("Please input factorial you would like to calculate: ")
ans = 1
for i in range(1,N+1,1):
ans = ans*i
print(ans)
Run Code Online (Sandbox Code Playgroud)
而我想添加一项功能来检查输入数字N是否为非负数.喜欢:
if N != int(N) and N < 0:
Run Code Online (Sandbox Code Playgroud)
我希望用户再次输入N,如果它不是非负数.
谢谢你的温柔帮助.