Computer Science, asked by 919361840785, 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 Afshabegum18
7

Answer:

This solution is for 4000 not for 3456

I know the solution for 4000 only

Sry

Answered by varshamittal029
0

Concept:

While loop is also known as a loop that has been pre-tested. A while loop, in general, allows a section of code to be run many times depending on a boolean state. It can be thought of as a repeated if statement.

Given:

def f(x):

   d=0

   while x >= 1:

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

       print(x,d)

   return(d)

print(f(3456))

Find:

What will be the value of f(3456)?

Solution:

In each iteration value of x will be checked and then the following statements will get executed.

In the first iteration:

x = 493.7142857142857 and d = 1

In the second iteration:

x = 70.53061224489797 and d = 2

In the third iteration:

x = 10.075801749271138  and d = 3

In the fourth iteration:

x = 1.439400249895877 and d = 4

In the fifth iteration:

x = 0.20562860712798242 and d = 5

Now the loop will end as x<1.

The final value of b will be 5.

∴ The value of f(3456) = 5

Similar questions