I tried to make this simple program to find factorial of inputted number.
But there is an error somewhere i could not figure out:
while i use raw_input()
function it displays 'none' output and if i use input()
function name error is displayed. Help me to find bug .
program_active=True
while program_active:
def fact(n):
if n==0:
return 1
elif not isinstance(n, int):
while not isinstance(n, int):
print "Factorial is defined only for Positive integers"
try:
n=int(raw_input())
except ValueError as ve:
pass
elif n<0:
print "Factorial is defined only for Positive integers"
else:
step1=fact(n-1)
step2=n*step1
return step2
print"input a number to check its factorial"
n=raw_input()
print fact(n)
print
print
print
print "do yo want to run the program again? (y/n)"
run=raw_input()
while run[0].upper()!='Y' and run[0].upper()!='N':
print"****invalid input****"
run=raw_input('say y/n \n')
if run[0].upper()=='N':
program_active=False
print "goodbye"
here is error while using raw_input()
function
> input a number to check its factorial
> 8
> Factorial is defined only for Positive integers
> 8
> None
>
>
>
> do yo want to run the program again? (y/n) n goodbye