Answer to Question #294232 in Python for black panthar

Question #294232
def h(n):
    s = 0
    for i in range(2,n):
        if n%i == 0:
           s = s+i
    return(s)






1
Expert's answer
2022-02-06T02:13:39-0500
#The function gets some argument n - Let's set n is 5 for example. 
def h(n):
    s = 0
#Then the function creates a sequence of numbers from 1 to n with range(1, n+1) function (result will be 1, 2, 3, 4, 5 in our case) and iterates over each of this numbers.
    for i in range(2,n):
#If remainder of dividing n to the number from the sequence greater then 0, variable s increments by 1.         
           if n%i == 0:
           s = s+i
# For our sequence we gets remainders 0, 1, 2, 1, 0 and variable s equal to 3. When the iteration complete, function returns s value.
    return(s)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS