What is the value of f(846) for the function below?
def f(x):
d=0
y=1
while y <= x:
d=d+1
y=y*3
return(d)
Answers
Given : def f(x):
d=0
y=1
while y <= x:
d=d+1
y=y*3
return(d)
To Find : value of f(846)
Explanation:
y = 1 < 846
=> d = 0 + 1 = 1
y = 1 * 3 = 3
3 < 846
=> d = 1 + 1 = 2
y = 3 * 3 = 9
9 < 846
=> d = 2 + 1 = 3
y = 9 * 3 = 27
27 < 846
=> d = 3 + 1 = 4
=> y = 27 * 3 = 81
81 < 846
=> d = 4 + 1 = 5
=> y = 81 * 3 = 243
243 < 846
=> d = 5 + 1 = 6
=> y = 243 * 3 = 729
729 < 846
=> d = 6 + 1 = 7
y = 729 * 3 = 2187
2187 > 846
Hence d = 7
f(846) Returns 7
value of f(846) = 7
Learn More:
In an infinite gp series the first term is p and infinite sum is s then p ...
https://brainly.in/question/12999165
Three unequal positive numbers a, b, c are in gp then prove that a + ...
https://brainly.in/question/12902761
- def f(x):
- d=0
- y=1
while y <= x:
- d=d+1
- y=y*3
- return(d)
value of f(846)
y = 1 < 846
- d= 0+1=1
y=1*3=3
3<846
- d=1+1=2
y = 3 *3 = 9
9<846
- d=2+1=3 y=9*3 = 27
27 < 846
- d=3+1=4
- y = 27 * 3 = 81
81 < 846
- d=4+1=5
- y = 81 * 3 = 243
243 < 846
- d=5+1=6
- y = 243 * 3=729
729 < 846
- d= 6 + 1 = 7
y=729* 3 = 2187
2187 > 846 Hence d = 7
f(846) Returns 7
value of f(846) = 7