Int vs Double on Python
Question: I'm in stats class right now and I wanted to know if it makes a difference if
you generate a number each digit at a time vs every digit at once, so I wrote
some code...

    
    
    from random import randint
    import math
    
    total1 = 0
    total2 = 0
    for i in range(100000):
        temp = 0
        for j in range(7):
            temp += randint(0,9)*math.pow(10,j)
        total1 += temp
        total2 += randint(0,9999999)
    
    print "avg1 = ", total1/100000
    print "avg2 = ", total2/100000
    

When I ran the code, avg1 was always a decimal and avg2 was always a whole
number. I don't understand why total1 is being considered as a double since I
only ever added integers to it...


Answer: According to the python documentation, the math.pow function returns a
floating point number. This is going to implicitly cast the temp variable to
be a float as well:

<https://docs.python.org/2/library/math.html>

Because total1 is implicitly cast as a float, while total2 is consistently
used as an int, total1 will return a decimal and total2 will return a whole
number.

