Hi there,

I'm new to Python and I've been writing a rudimentary exercise in
Deitel's Python: How to Program, and I found that this code exhibits a
weird behavior. When I run the script, the for...range(1,11) structure
always starts with zero--and I've tried plugging other values as well!
>From the Python commandline, though, this structure produces a normal
1,2,3,4,5,6,7,8,9,10 output. Can anyone tell me what I am doing wrong
here?

input = raw_input("Please enter a value you wish to factorialize:")

def fact(n):
        total = 0
        n = int(n)
        while n > 0:
                total *= n
                n -=1
        return total

print "%d" % fact(input)

e = 1
for val in range(1,11):
        if val == 0:
                continue
        else:
                e += 1/fact(val)

print "Where n is 10, e = %d\n\n" % e


e2 = 1
input = raw_input("Enter x:")

for val in range(1,11):
        if val == 0:
                continue
        else:
                e2 += (float(input) ** val)/(fact(val))

print "Where the n is 10, e**x = %d\n\n" %e
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to