+ 2
What does f(31415927) return, for the following function definition?def f(x): d=0 while x > 1: (x,d) = (x/2,d+1) return(d)
ans thz question guys plz
6 Antworten
+ 25
Answer is 25
the while loop will run 25 times
as 31415927 / 2**24 =1.8... which is > 1
so for last time it will go
for 2**25 , d will be incremented 24+1=25
then it becomes less than 1
condition becomes false... while loop terminates
-->the no. of times x is divided by 2 & remains >1
the d will be incremented by 1
0
1
0
What does h(3231) return for the following function definition?
def h(x): (m,a) = (1,0) while m <= x: (m,a) = (m*2,a+1) return(a)
0
What does h(3231) return for the following function definition?
def h(x):
(m,a) = (1,0)
while m <= x:
(m,a) = (m*2,a+1)
return(a)
0
What does f(27182818) return, for the following function definition?
def f(x):
d=0
while x > 1:
(x,d) = (x/2,d+1)
return(d)
- 1
def f(x):
d=0
while x >= 1:
(x,d) = (x/4,d+1)
return(d)