Problem solving with Python Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

40.) What is the output? def sub(i,j): if (i==0): return j else: return sub(i-1, j-1) print (sub (4,10)) - 20 - -3 - 0 - Infinite loop

0

42.) What is the output? def test(n): if n == 0: return 0 elif n ==1: return 1 else: return test(n-1) + test(n-2) for i in range (0,4): print(test(i), end=' ') -0 1 2 3 -1 2 3 4 -0 1 1 2 3 -0 1 1 2

0112

43.) What does the following function print for n1=12 and n2=15? def div(n1, n2): if n1 % n2 == 0: return n2 else: return div(n2, n1 % n2) - 12 - 15 - 3 - 9

3

26.) How many times is the function count_down() called in the below code? def count_down(count): if count == 1: print('Terminated..!') else: print(count) count_down(count-1) count_down(5)

6 times

54.) What is the output? def print_number(a): try: print(f'[a:.2f]') except: print('Cannot print the value') print_number('10') print_number(2.0)

Cannot print the value Will print a value

25.) What is the output? def divide by two (count): if count == 1: print('Terminated..!') else: print(count) divide_by_two(count/2) divide_by_two(9) -9 4.5 2.25 1.125 Terminated..! -9 4.5 2.25 Terminated..! -Infinite loop -9 4.5 2.25 1.125

Infinite loop

37.) A base case is a __________. -case that returns a value without performing a recursive call -function method that calls itself -function execution instance that calls another execution instance of the same function -case that calls another function method

case that returns a value without performing a recursive call

57.) Which of the following is the correct syntax for a multiple exception handler? -except (NameError, AttributeError): -except [NameError, AttributeError]: -except NameError AttributeError: -except NameError, AttributeError:

except (NameError, AttributeError):

30.) Assume that there is a recursive binary search function find(). If a sorted list has a data structure with indices 0 to 50 and the item being searched for happens to be at a location 6, write each call of find() that would occur while searching for that item. The first is find(0,50). -find(0,50) find(0,12) find(0,6) -find(0,50) find(0,12) -find(0,50) -find(0,50) find(0,12) find(0,6) find(0,3)

find(0,25) find(0,12)

27.) Define a base case condition to find the sum of arithmetic progression of the function. def arith_sum(a1, diff, nth): XXX return 0 else: return a1 + arith_sum(a1 + diff, diff, nth-1)

if nth == 0:

10.) Which property is required for plt.legend()? -alpha -data -visible -lable

lable

16.) Select the line of code which is a 2-D array. -np.array([1, 2, 3, 4, 5]) -np.array([1, 2, 3, 4, 5], [6, 7, 8, 9, 10]) -np.array((1, 2, 3, 4, 5), (6, 7, 8, 9, 10)) -np.array([(1, 2, 3, 4, 5), (6, 7, 8, 9, 10)])

np.array([(1, 2, 3, 4, 5), (6, 7, 8, 9, 10)])

19.) Identify the code used for matrix multiplication of two arrays. -np.mat(array1, array2) -np.dot(array1, array2) -np.malmul(array1, array2) -np.cross(array1, array2)

np.dot(array1, array2)

18.) Which numpy function creates the sequence [0.4,0.5,0.6,0.7]? -np.linspace(0.4,0.7,4) -np.range(0.4,0.7,4) -np.arange(0.4,0.7,4) -np.array(0.4,0.7,4)

np.linspace(0.4,0.7,4))

13.) Which is incorrect syntax for axvline() function? -plt.avxline('Text') -plt.avxline(x, ymin, ymax, 'Text') -plt.axvline(y, xmin, xmax, linewidth = 1, color = 'r') -plt.axvline('Text', color = 'blue', fontsize=10)

plt.axvline(y, xmin, xmax, linewidth = 1, color = 'r')

7.) Select format string used to style the lines as shown in the image (blue dashed line & red plus sign line) -r+ and b- -r+ and b-- -r++ and b-- -r+ and c-

r++ and b--

28.) Complete the code to get a factorial number. def factorial(number): if number == 0: return 1 else: XXX

return number*factorial(number - 1) print(factorial(5))

8.) In plt.plot (X, Y, color='ro-', linewidth=5, markersize=5, alpha=0.35), which property is defined by alpha? -transparency -anti-aliasing -color contrast -animation

transparency

38.) Which condition is the recursive case for sum of the first n natural numbers? def nsum(n): if num == 0: sum = 0 elif n == 1: sum = 1 else: sum = n + nsum(n-1) return sum

sum = n + nsum(n-1)


Conjuntos de estudio relacionados

Lab 24: Endocrine System Physiology I

View Set

Section 28: Pricing and Commission Calculations

View Set

CompTIA Security+ (SY0-601) Practice Exam #6

View Set

Management 3020 Chapters 3, 4 & 5

View Set

Mankiw Brief Principals of Economics Chapter 16

View Set

prep 3 & 4: consequences of climate change

View Set

Chapter 16: Endocrine Glands & Abbreviations

View Set