TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments:
1)a function `g` representing an increasing function g(x)
2) a number `gmin`,
and returns an integer `nmin` such that nmin>0
is the smallest integer that satisfies g(nmin)>gmin.
test:
def g(n): return 2*n print(lowest_integer(g, 10))
Output: 6
code in python (code to copy)
def lowest_integer(g, num):
# Initialize the nmin value to 1
nmin=1
# loop until g(nmin) is less than or equal to num
while(g(nmin)<=num):
# increment nmin each time
nmin=nmin+1
# return nmin as the result
return nmin
def g(n):
return 2*n
print(lowest_integer(g, 10))
code screenshot
sample console output screenshot
Get Answers For Free
Most questions answered within 1 hours.