What is the value of g(728) for the function below?
def g(y):
b = 0
while y >= 3:
(y,b) = (y/3,b+1)
return(b)
if u guys know about python pls help me plsss !!!!!
Answers
Answer:
5
Explanation:
y = 728
b = 0
while y >= 3:
(y,b) = (y/3,b+1)
print(b)
Output : 5
Hope this helps.
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 g(y):
b = 0
while y >= 3:
(y,b) = (y/3,b+1)
return(b)
print(g(728))
Find:
What will be the value of g(728)?
Solution:
In each iteration value of y will be checked and then the following statements will get executed.
In the first iteration:
y = 242.66666666666666 and b = 1
In the second iteration:
y = 80.88888888888889 and b = 2
In the third iteration:
y = 26.962962962962962 and b = 3
In the fourth iteration:
y = 8.987654320987653 and b = 4
In the fifth iteration:
y = 2.995884773662551 and b = 5
Now the loop will end as y<3.
The final value of b will be 5.
∴ The value of g(728) = 5