Answer to Question #161103 in Python for Kathir

Question #161103

What is h(41)-h(40), given the definition of h below?

def h(n):
    s = 0
    for i in range(1,n+1):
        if n%i > 0:
           s = s+1
    return(s)
1
Expert's answer
2021-02-03T16:36:09-0500

Solution:

Loop (for i in range(1,n+1):) for h(41):

n % i = 41 % 2 = 1, s = 1
n % i = 41 % 3 = 2, s = 2
n % i = 41 % 4 = 1, s = 3
n % i = 41 % 5 = 1, s = 4
n % i = 41 % 6 = 5, s = 5
n % i = 41 % 7 = 6, s = 6
n % i = 41 % 8 = 1, s = 7
n % i = 41 % 9 = 5, s = 8
n % i = 41 % 10 = 1, s = 9
n % i = 41 % 11 = 8, s = 10
n % i = 41 % 12 = 5, s = 11
n % i = 41 % 13 = 2, s = 12
n % i = 41 % 14 = 13, s = 13
n % i = 41 % 15 = 11, s = 14
n % i = 41 % 16 = 9, s = 15
n % i = 41 % 17 = 7, s = 16
n % i = 41 % 18 = 5, s = 17
n % i = 41 % 19 = 3, s = 18
n % i = 41 % 20 = 1, s = 19
n % i = 41 % 21 = 20, s = 20
n % i = 41 % 22 = 19, s = 21
n % i = 41 % 23 = 18, s = 22
n % i = 41 % 24 = 17, s = 23
n % i = 41 % 25 = 16, s = 24
n % i = 41 % 26 = 15, s = 25
n % i = 41 % 27 = 14, s = 26
n % i = 41 % 28 = 13, s = 27
n % i = 41 % 29 = 12, s = 28
n % i = 41 % 30 = 11, s = 29
n % i = 41 % 31 = 10, s = 30
n % i = 41 % 32 = 9, s = 31
n % i = 41 % 33 = 8, s = 32
n % i = 41 % 34 = 7, s = 33
n % i = 41 % 35 = 6, s = 34
n % i = 41 % 36 = 5, s = 35
n % i = 41 % 37 = 4, s = 36
n % i = 41 % 38 = 3, s = 37
n % i = 41 % 39 = 2, s = 38
n % i = 41 % 40 = 1, s = 39

 h(41)=39

Loop (for i in range(1,n+1):) for h(40):

n % i = 40 % 3 = 1, s = 1
n % i = 40 % 6 = 4, s = 2
n % i = 40 % 7 = 5, s = 3
n % i = 40 % 9 = 4, s = 4
n % i = 40 % 11 = 7, s = 5
n % i = 40 % 12 = 4, s = 6
n % i = 40 % 13 = 1, s = 7
n % i = 40 % 14 = 12, s = 8
n % i = 40 % 15 = 10, s = 9
n % i = 40 % 16 = 8, s = 10
n % i = 40 % 17 = 6, s = 11
n % i = 40 % 18 = 4, s = 12
n % i = 40 % 19 = 2, s = 13
n % i = 40 % 21 = 19, s = 14
n % i = 40 % 22 = 18, s = 15
n % i = 40 % 23 = 17, s = 16
n % i = 40 % 24 = 16, s = 17
n % i = 40 % 25 = 15, s = 18
n % i = 40 % 26 = 14, s = 19
n % i = 40 % 27 = 13, s = 20
n % i = 40 % 28 = 12, s = 21
n % i = 40 % 29 = 11, s = 22
n % i = 40 % 30 = 10, s = 23
n % i = 40 % 31 = 9, s = 24
n % i = 40 % 32 = 8, s = 25
n % i = 40 % 33 = 7, s = 26
n % i = 40 % 34 = 6, s = 27
n % i = 40 % 35 = 5, s = 28
n % i = 40 % 36 = 4, s = 29
n % i = 40 % 37 = 3, s = 30
n % i = 40 % 38 = 2, s = 31
n % i = 40 % 39 = 1, s = 32

h(40)=32


So, h(41)-h(40)=39-32=7


Answer:

h(41)-h(40)=7


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