Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

python3... please help :) def sum_divisors (n) : Given a positive integer n, cal

ID: 3755540 • Letter: P

Question

python3... please help :)

def sum_divisors (n) : Given a positive integer n, calculate and return the total of all of its positive divisors. Note: n is also a divisor of itself. o Assume: n is a positive integer o Restrictions: remember, you may not call sum() sum-divisors(6) sum-divisors(1) sum-divisors(7) 12 1 8 # divisors: # only divisor: 1 # divisors : 1,2,3,6 1,7 def pi(precision): One can approximate the value of pi by using the Leibniz formula (given below) that calculates a theoretically infinite sum. In practice, though, we run a finite summation where the larger the number of terms the better the approximation of pi. Given precision as a float, this function approximates the value of pi using the Leibniz formula. The function should stop the infinite summation when the improvement of the approximation becomes smaller than the provided precision 01)44 4 4 4 4 2k1 3'5 79 11 Leibniz formula (source: http://forum.codecall.net/uploads/monthly_03_2012/post-80377-13333829507556.png) Assume: precision is a positive float value Restrictions: you must use a loop in your implementation to receive credit. o o 3.466666666666667 # total of the first three terms since 4/5

Explanation / Answer

def sum_divisors(n) :
# Final result of summation of divisors
result = 0
  
# find all divisors which divides 'num'
for i in range(2, n):
if (n % i)==0:
result = result + i

#if the number is 1 return 1.
if(n == 1):
return n

# Add 1 and the number to the result as 1 is also a divisor
return (result + 1 + n);


def minmax (nums):
if(len(nums)==0):
return 0
minimum = maximum = nums[0]
for i in nums[1:]:
if i < minimum:
minimum = i
else:
if i > maximum: maximum = i
  
if maximum < 0 or minimum < 0 :
return (abs(minimum) + abs(maximum))
else :
return maximum - minimum