def number(n):
result = 1
for i in range(1, n+1):
result = result * i
return result
In the above code, what is the "parameter?"
Paremeter is the variable which are inside the function definition parenthesis .
Here number is parenthesis and n is parameter
def number(n): result = 1 for i in range(1, n+1): result = result * i return...
Question 18 CLO3 Analyze the following code and answer the questions that follow def F(n): If n <= 1: return n else: return F(n-1)+F(n-2) for i in range (n) print (F(i)) Result: 0 1 1 2 3 5 8 13 a. Write number of operations as a function when the code is execute b If n 7, what is the total number of operations? c. What is the complexity of the algorithm behind the code? (2 Marks) (2 Marks) (1...
def hash_or_dash(limit): result - for i in range(limit): if i * 2 = @: result # elif i % 3 -- : result - return result print(hash_or_dash(7) #-##-## ##-## none of the above MacBook Pro
pointsConsider this code def f (n,p): for i in range(n): for j in range(i,p): for k in range(n*p): dosomething(i,j,k) + dosomething(j,i,k) Write down the number of calls to dosomething T(n, p) in summation notation
I need to rewrite this code without using lambda function using python. def three_x_y_at_one(x): result = (3 * x *1) return result three_x_y_at_one(3) # 9 zero_to_four = list(range(0, 5)) def y_values_for_at_one(x_values): return list(map(lambda x : three_x_y_at_one(x), x_values)) -------> this is the function that I need to rewrite without using a lambda function . y_values_for_at_one(zero_to_four) # [0, 3, 6, 9, 12] Thanks
What is the result of the following: print(input("Enter a number")* 2) if you entered 9. oooo 13 Error What is the result of t = (1, 3.5): t.append(7) O (1,3,5,7) O (1,3,5) O (7) Error To check if there is a WIN in a tic-tac-toe game, the program has to check * O 6 lines of 3 boxes O 8 lines of 3 boxes O 9 boxes O The Center What is the result of print( int("3" + "5") +...
In Python State g(n)'s runtime complexity: def f(n): if n <= 1:` return 1 return 1 + f(n/2) def g(n): i = 1 while i < n: f(i) i *= 2
Help with solution using Python test using def riffle_generator(seed): random.seed(seed) for i in range(1000): n = random.randint(0, 100) items = [random.randint(0, 10**6) for j in range(2 * n)] yield (items, True) yield (items, False) Riffle def riffle(items, out True): Given a list of items that is guaranteed to contain an even number of elements (note that the integer zero is an even number), create and return a list produced by performing a perfect riffle to the items by interleaving the...
PYTHON QUESTION Given the following function: def sort(A, n): for i in range (1, n): for j in range(i-1, -1,-1): if A[j + 1] > A[j]: t = A[j+1] A[j+1] = A[j A[j] = t What would the output be for the following array: A = [3, 10, 2, 8,15]; where n = 5; for each iteration of i (i.e. when i = 1, i=2, i=3, i=4)? A. 10, 3, 2, 8, 15 B....
The following Implementation of the Fibonacci function is a correct, but inefficient, def fibonacci(n): if n <= 2: return 1 else: return fib(n - 1) + fib(n - 2) In more details, the code shown runs very slowly for even relatively small values of n; it can take minutes or hours to compute even the 40th or 50th Fibonacci number. The code is inefficient because it makes too many recursive calls. It ends up recomputing each Fibonacci number many times....
Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that calls this function and uses keyword arguments to pass ‘testing’ into x and 2 into y. b. What will be printed when the function call executes? 6. Write a statement that generates a random number in the range I'm using python to solve this this is what i did def main(): result= my_function(x='testing', y=2) print(result) def my_function(x,y): return x[y] main()