Computer Science, asked by babydoll2016rd, 2 days ago

What is the value of f(3456) for the function below?
def f(x):
d=0
while x >= 1:
(x,d) = (x/7,d+1)
return(d)

Answers

Answered by rishita29gupta
2

Answer:

def f(x):

     d=0

     while x >= 1:

         (x,d) = (x/7,d+1)

     return(d)

f(3456)

output:-

5

Explaination:-

x=3456>=1    d=0

so, condition applies (x/7,d+1)=(493.71,1)

x=493.71>=1   d=1

again, condition applies (x/7,d+1)=(70.53,2)

x=70.53>=1   d=2

again, condition applies (x/7,d+1)=(10.07,3)

x=10.07>=1   d=3

again, condition applies (x/7,d+1)=(1.43,4)

x=1.43>=1   d=4

again, condition applies (x/7,d+1)=(0.20,5)

x=.20<=1   condition fails

So, return(d) which is 5

Similar questions