Comp Sci 2 - Exam 2

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

58) Select the format string used to style the lines as shown in the image. a. r+ and b- b. r+ and b-- c. r++. and b-- d. r+ and c-

b. r+ and b--

22) Select an assertion method that checks if a string is not a substring of another string. a. assertIsNot b. assertFalse c. assertNotIn d. assertNotEqual

c. assertNotIn

43) What is 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=' ') a. 0 1 2 3 b. 1 2 3 4 c. 0 1 1 2 3 d. 0 1 1 2

d. 0 1 1 2

53) Which function plots data onto the graph? a. plt.show() b. plt.imshow() c. plt.legend() d. plt.plot()

d. plt.plot()

45) What is the role of sys.getrecursionlimit()? a. It measures the maximum depth of the function. b. It changes the depth of the function. c. It isolates the defined function. d. It finds the error of the function.

a. It measures the maximum depth of the function.

9) A derived class may define a method having the same name as the base class means that: a. a derived class method overrides the method of the base class. b. a base class method overrides the method of the derived class. c. the functionality of the method is the same in both derived and base class. d. a derived class method overloads the method of the base class.

a. a derived class method overrides the method of the base class.

69) Which numpy function creates the sequence [0.4,0.5,0.6,0.7]? a. np.linspace(0.4,0.7,4) b. np.range(0.4,0.7,4) c. np.arange(0.4,0.7,4) d. np.array(0.4,0.7,4)

a. np.linspace(0.4,0.7,4)

71) The pyplot.axis() function is used to define the _____. a. range of the axes b. position of the axes c. scale of the axes d. rotation of the axes

a. range of the axes

30) How many times is the recursive function find() called when searching for the missing letter 'A' in the below code? def find(lst, item, low, high): range_size = (high - low) + 1 mid = (high + low) // 2 if item == lst[mid]: pos = mid elif range_size == 1: pos = -1 else: if item < lst[mid]: pos = find(lst, item, low, mid) else: pos = find(lst, item, mid+1, high) return pos listOfLetters = ['B', 'C', 'D', 'E', 'F', 'G', 'H'] print(find(listOfLetters, 'A', 0, 6)) a. 4 b. 3 c. 5 d. program gets into an infinite loop

b. 3

2) Class Healthcare has the methods Pharmacy() and Labs(). Class Hospitals is derived from Healthcare and has the methods Doctor(), Patients(), and Nurses(). After h =Hospitals()executes, how many different methods can object h call, ignoring constructors? a. 7 b. 5 c. 3 d. 4

b. 5

17) _____ are classes that provide additional behavior to methods and are not themselves meant to be instantiated. a. Derived classes b. Mixin classes c. Base classes d. Inheritance classes

b. Mixin classes

68) What doesnp.ones((3, 2))create? a. [[1. 1. 1.] [1. 1. 1.]] b. [(1. 1.) (1. 1.) (1. 1.)] c. [[1. 1.] [1. 1.] [1. 1.]] d. [(1. 1. 1.) (1. 1. 1.)]

b. [(1. 1.)(1. 1.)(1. 1.)]

3) Which of the following is an example of a derived class? a. class item: def _init_(self): self.name = ''self.quantity = 0 self.expiration = '' b. class Item:def __init__(self): self.name = '' self.quantity = 0 class Produce(Item): def__init__(self): Item.__init__(self) self.expiration = '' c. Class item(): def __init__(self): self.name = '' self.quantity = 0 Produce(Item): def__init__(self): Item.__init__(self) self.expiratIon = '' d. class Item: def __init__(self): self.name = '' self.quantity = 0 class Produce(Item): def__init__(self): Item.__init__(self) self.expiration = ''

b. class Item:def __init__(self): self.name = '' self.quantity = 0 class Produce(Item): def__init__(self): Item.__init__(self) self.expiration = ''

66) Which package provides tools for scientific and mathematical computations in Python? a. pandas b. numpy c. sklearn d. matplotlib

b. numpy

10) Complete the code to generate the following output. Inside the child class class ParentClass: def action(self): print('Method is not overridden') class ChildClass(ParentClass): def action(self): print('Inside the child class') if __name__ == '__main__': XXX a. ParentClass(self).action() b. r = ChildClass() r.action() c. ChildClass(self).action() d. r = ParentClass() r.action()

b. r = ChildClass() r.action()

50) Identify the error in the code that scrambles a word's letters in all the possible ways.. def scramble(r_letters, s_letters): if len(r_letters) == 0: print(s_letters) else: for i in range(len(r_letters)):scramble_letter = r_letters[i]remaining_letters = r_letters[:i] + r_letters[i-1:] scramble(remaining_letters, s_letters + scramble_letter) scramble('abc','') a. scramble_letter = r_letters[i] b. remaining_letters = r_letters[:i] + r_letters[i-1:] c. scramble(remaining_letters, s_letters + scramble_letter) d. if len(r_letters) == 0

b. remaining_letters = r_letters[:i] + r_letters[i-1:]

24) A programmer is testing individual components of a program, including methods, class interfaces, data structures, and inherited attributes. What type of testing is the programmer performing? a. Component testing b. Suite testing c. Unit testing d. Functionality testing

c. Unit testing

13) Identify which relationship of the everyday items is a has-a relationship. a. Baseball/Sport b. Truck/Vehicle c. University/Library d. Aspirin/Medicine

c. University/Library

52) Which package is used for plotting in Python? a. matlab b. ggplot c. matplotlib d. matlablib

c. matplotlib

29) Complete the code to get a factorial of a number. def factorial(number): if number == 0: return 1 else: XXX print(factorial(4)) a. return number*(number-1) b. return factorial(number)*factorial(number-1) c. return number*factorial(number-1) d. return (number-1)*(number-2)

c. return number*factorial(number-1)

5) Identify the base class for the other classes in the given statement. Planet is derived from SolarSystem; SolarSystem is derived from Galaxy; Galaxy is derived from Universe. a. SolarSystem b. Planet c. Galaxy d. Universe

d. Universe

37) An indent variable _____ number of spaces on each iteration. a. adds unequal b. removes unequal c. removes equal d. adds equal

d. adds equal

21) Select the assertion method that checks if a number is greater than or equal to another number. a. assertNotLess b. assertGreater c. assertAlmostEqual d. assertGreaterEqual

d. assertGreaterEqual

55) What is output? import matplotlib.pyplot as plt Salary=[x*x for x in range(-70,70,1)] Grade=[x for x in range(-70,70,1)] plt.plot(Grade,Salary,'c-') plt.title('X vs Y') plt.xlabel('X') plt.ylabel('Y') plt.show() a. b. c. d.

a.

27) 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) a. 5 b. 6 c. 4 d. 3

a. 5

11) Complete the code to generate the following output. 16 8 class Rect(): def __init__(self,length,breadth): self.length = length self.breadth = breadth def getArea(self): print(self.length*self.breadth) class Sqr(Rect): def __init__(self,side): self.side = side Rect.__init__(self,side,side) def getArea(self): print(self.side*self.side) if __name__ == '__main__': XXX a. square = Sqr(4) rectangle = Rect(2,4) square.getArea() rectangle.getArea() b. rectangle = Rect(2,4) square = Sqr(4) rectangle.getArea() square.getArea() c. Sqr().getArea(4) Rect().getArea(2,4) d. Rect(4).getArea() Sqr(2,4).getArea()

a. square = Sqr(4)rectangle = Rect(2,4)square.getArea()rectangle.getArea()

59) Inplt.plot(X, Y, color='ro-', linewidth=5, markersize=5, alpha=0.35), which property is defined by alpha? a. transparency b. anti-aliasing c. color contrast d. animation

a. transparency

41) What is output? def sub(i,j): if(i==0): return j else: return sub(i-1,j-i) print(sub(4,10)) a. 20 b. -3 c. 0 d. Infinite loop

c. 0

34) How many iterations are needed for the function to find 12? def Find(list, ele, low, high): if high >= low: mid = (high + low)//2 if list[mid] == ele: return mid elif list[mid] > ele: return Find(list, ele, low, mid-1) else: return Find(list, ele, mid + 1, high) else: return -1listOfNumbers = [11, 12, 13, 15, 18]result = Find(listOfNumbers,12,0,(len(listOfNumbers)-1)) print(result) a. 4 b. 3 c. 2 d. 1

c. 2

44) 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) print(div(12,15)) a. 12 b. 15 c. 3 d. 9

c. 3

25) If the base condition is not defined in the recursive function, _____. a. the program runs only once b. the program runs as many times as the number passed as its argument c. the program terminates giving an error d. the program gets into an infinite loop

d. the program gets into an infinite loop

1) _____ is a concept where the derived class acquires the attributes of its base class a. Encapsulation b. Inheritance c. Abstraction d. Polymorphism

Inheritance

4) Which statement is true about inheritance? a. A derived class cannot serve as a base class for another class. b. A class can serve as a base class for multiple derived classes. c. A class can be derived from only one class. d. A class can serve as a base class for only one class.

b. A class can serve as a base class for multiple derived classes.

40) How many times is the function Info() called if the user enters 0 and 1 in the first attempt? def Info(num1, num2): if (num1 == 0) or (num1 == 1): print('Passed round 1.') if (num2 == 1) or (num2 == 0): print('Passed round 2.') print('Good. You know your binary digits!') else: print('Numbers can be only 0s or 1s...Enter again') arg1 = int(input())arg2 = int(input())Info(arg1, arg2) else:print('Numbers can be only 0s or 1s...Enter again') arg1 = int(input())arg2 = int(input())Info(arg1, arg2) print('Enter 2 numbers used in binary notation') user_val1 = int(input()) user_val2 = int(input()) Info(user_val1, user_val2) a. 1 b. 2 c. 0 d. none

a. 1

15) Identify which relationship of the everyday items is an is-a relationship. a. Basketball/Sport b. Car/Transmission c. Calculator/Display d. Pizza/Topping

a. Basketball/Sport

19) Identify the concept used in the following code. class Coach: def __init__ (self, cname): self.coach_name = cname class Player: def __init__ (self, pname): self.player_name = pname class Game (Player, Coach): def __init__ (self, gname, pname, cname): Player.__init__ (self,pname) Coach.__init__ (self,cname) self.game = gname def get_game (self):print (self.game, self.player_name, self.coach_name) a. Multiple inheritance b. Multilevel inheritance c. Inheritance using mixins d. Inheritance using derived class

a. Multiple inheritance

12) What is output? class Item: def __init__(self): self.name = 'None' self.quantity = 0 def dsp_item(self): print(f'Name: {self.name}, Quantity: {self.quantity}') class Produce(Item): # Derived from Item def __init__(self): Item.__init__(self) # Call base class constructor self.expiration = '01-01-2000' def dsp_item(self): Item.dsp_item(self) print(f'Expiration: {self.expiration}') n = Produce() n.dsp_item() a. Name: None, Quantity: 0 Expiration: 01-01-2000 b. Expiration: 01-01-2000 c. dsp_item() returns a AttributeError d. Expiration: 01-01-2000 Expiration: 01-01-2000

a. Name: None, Quantity: 0 Expiration: 01-01-2000

46) Which of the following is a good candidate for using recursive functions? a. To solve the greatest common divisor (GCD) problem b. To solve problems that have a true and false solution c. To solve problems that require excessive memory allocation d. To solve logarithmic problems

a. To solve the greatest common divisor (GCD) problem

49) What is the output ofscramble('ab', '')in the following code? def scramble(r_letters, s_letters): if len(r_letters) == 0: print(s_letters) else: for i in range(len(r_letters)):scramble_letter = r_letters[i]remaining_letters = r_letters[:i] + r_letters[i+1:] scramble(remaining_letters, s_letters + scramble_letter) scramble('ab','') a. ab ba b. null c. ab null d. Null ab

a. ab ba

20) Select an assertion that checks if the string contains 'war' for the given code block. def test_eq(self): self.[XXX] a. assertIn( 'war', 'In war, events of importance are the result of trivial causes.') b. assertIs( 'war', 'In war, events of importance are the result of trivial causes.') c. assertAlmostEqual( 'war', 'In war, events of importance are the result of trivial causes.') d. assertIn( 'In war, events of importance are the result of trivial causes.', 'war')

a. assertIn( 'war', 'In war, events of importance are the result of trivial causes.')

38) A base case is a _____. a. case that returns a value without performing a recursive call b. function method that calls itself c. function execution instance that calls another execution instance of the same function d. case that calls another function method

a. case that returns a value without performing a recursive call

31) 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 location 6, write each call of find() that would occur while searching for that item. The first is find(0,50). a. find(0, 25) find(0, 12) find(0, 6) b. find(0, 25) find(0, 12) c. find(0, 25) d. find(0, 25) find(0, 12) find(0, 6) find(0, 3)

a. find(0, 25) find(0, 12) find(0, 6)

28) Define a base 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) a. if nth == 0: b. if nth >= 0: c.if a1 >= 0: d.if a1 == 0:

a. if nth == 0:

65) Identify the correct syntax to annotate the data point at (5,2) placing the text 'Peak' at (5,3). a. plt.annotate('Peak', xy=(5, 2), xytext=(5, 3)) b. plt.annotate('Peak', xy=(5, 3), xytext=(5, 2)) c. plt.annotate(xy=(5, 2), xytext=(5, 3)) d. plt.annotate(xy=(5, 3), xytext=(5, 2))

a. plt.annotate('Peak', xy=(5, 2), xytext=(5, 3))

64) Which is incorrect syntax for axvline() function? a. plt.axvline('Text') b. plt.axvline(x, ymin, ymax, 'Text') c. plt.axvline(y, xmin, xmax, linewidth=1, color='r') d. plt.axvline('Text', color='blue', fontsize=10)

a. plt.axvline('Text')

54) Identify the (x[2], y[2]) coordinate in the following code. import matplotlib.pyplot as plt Salary=[10,20,30,40,50] Grade=[1,2,3,4,5] plt.plot(Salary,Grade) plt.title('Salary vs Grade') plt.xlabel('Salary') plt.ylabel('Grade') plt.show() a. (30, 3) b. (20, 2) c. (10, 1) d. (40, 4)

b. (20, 2)

7) How many different methods can Medicine object item2 call? class Product: def __init__(self): self.name = 'None' self.quantity = 0 def set_item(self, nm, qty): self.name = nm self.quantity = qty def get_item(self): return self.name, self.quantity def get_name(self): return self.name def get_quantity(self): return self.quantity class Medicine(Product): def__init__(self): Product.__init__(self) self.expiration = 2000 def set_expiration(self, exp): self.expiration = exp def get_medicine(self): return self.name, self.quantity, self.expiration item1 = Product() item2 = Medicine() a. 2 b. 6 c. 4 d. 8

b. 6

48) Recursive exploration does not explore _____. a. all possible reorderings of a word's letters b. all the subsets of items c. all possible paths between cities d. only one possible choice

d. only one possible choice

8) What is the output of the following code if the user enters '1' and '9'? class Players: def __init__(self, name, age): self.name = name self.age = age def info(self): print(f'Info for player {self.name}') class SoccerPlayers(Players): def __init__(self, name, age, league): Players.__init__(self, name, age) self.league = league def teamNum(self, num1): if num1 == 0: print('Cannot be this number') else: print(f'\n{self.name} plays at {num1}') class ArcadePlayer(SoccerPlayers): def __init__(self, name, age, league, city): SoccerPlayers.__init__(self, name, age, league) def professional(self): print('Too good!') choice = input('Select the number 1 or 2: ') num = int(input('Enter which number do you play: ')) player1 = ArcadePlayer('Timothy', 55, 'MyLeague', 'Chicago') player2 = ArcadePlayer('Sally', 20, 'L', 'New York') player1.info() player2.info() play = player1 if (choice == 1) else player2 play.teamNum(num) a. Info for player Sally Sally plays at 9 b. Info for player Timothy Info for player Sally Sally plays at 9 c. Info for player Timothy Info for player Sally Sally plays at 9 Timothy plays at 9 d. Timothy plays at 1 Sally plays at 9

b. Info for player TimothyInfo for player SallySally plays at 9

72) What needs to be provided for the pyplot.subplot() function arguments? a. Plot location and figure name b. Rows, columns, and active subplot c. Plot number and figure name d. Total number of plots and active subplot

b. Rows, columns, and active subplot

23) Select the non-existent assertion method. a. assertNotIn b. assertNone c. assertFalse d. assertTrue

b. assertNone

14) Which is an example of composition? a. class Continent:def __init__(self): self.name = '' class Europe(Continent): def __init__(self): Continent.__init__(self) self.area = '' self.population = '' class Africa(Continent): def __init__(self): Continent.__init__(self) self.area = '' self.population = '' b. class Cars:def __init__(self): self.type = '' self.Make = '' class Toyota(Cars): def __init__(self): Cars.__init__(self) self.cost = '' self.features ='' class Bikes: def __init__(self): self.Make = '' class Kawasaki(Bikes): def __init__(self): Bikes.__init__(self) self.cost = '' self.features ='' self.type = '' c. class Fruit:def __init__(self): self.name = '' class Apple: def __init__(self): self.type = '' self.nutrition = '' d. class Laptop:def __init__(self): self.brand = '' self.processor = '' class Processor: def __init__(self): self.brand = '' self.cores = '' self.speed = ''

b. class Cars:def __init__(self):self.type = ''self.Make = '' class Toyota(Cars):def __init__(self): Cars.__init__(self) self.cost = '' self.features =''class Bikes: def __init__(self):self.Make = '' class Kawasaki(Bikes):def __init__(self): Bikes.__init__(self) self.cost = '' self.features ='' self.type = ''

51) A traveller starts his journey from Chicago and travels to Los Angeles, New York, California, and Florida. Which XXX is the best recursive exploration method to find the distance the traveller travelled? def distance_travel(curr_path, need_to_visit): if len(curr_path) == num_cities: total_distance = 0 for i in range(len(curr_path)): print(f'{city_names[curr_path[i]]}. ', end=' ') if i > 0: total_distance += distances[curr_path[i- 1]][curr_path[i]] print(f'= {total_distance}') else: for i in range(len(need_to_visit)): city = need_to_visit[i] XXX need_to_visit.insert(i, city) curr_path.pop() a. distance_travel(curr_path, need_to_visit) need_to_visit.pop(i) curr_path.append(city) b. distance_travel(curr_path, need_to_visit) need_to_visit.append(city) curr_path.pop(i) c. need_to_visit.append(city) curr_path.pop(i) distance_travel(curr_path, need_to_visit) d. need_to_visit.pop(i) curr_path.append(city) distance_travel(curr_path, need_to_visit)

b. distance_travel(curr_path, need_to_visit)need_to_visit.append(city)curr_path.pop(i)

36) While adding output statements to debug recursive functions, _____ the print statements to show the current depth of recursion. a. left align b. indent c. right align d. center align

b. indent

70) Identify the code used for matrix multiplication of two arrays. a. np.mat(array1, array2) b. np.dot(array1, array2) c. np.malmul(array1, array2) d. np.cross(array1, array2)

b. np.dot(array1, array2)

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

b. sum = n + nsum(n-1)

74) Which code block generates the following output? a. theta1 = np.linspace(0, 2*np.pi, 100) r=1 plt.subplot(1)plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2)plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(3)plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(4)plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.show() b. theta1 = np.linspace(0, 2*np.pi, 100) r=1 plt.subplot(2, 2, 1) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 2) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 3) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 4) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.show() c. theta1 = np.linspace(0, np.pi, 100) r=1 plt.subplot(2, 2, 1) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 2) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 3) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 4) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.show() d. theta1 = np.linspace(0, 2*np.pi, 100) r=1 plt.subplot(4, 1) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(4, 2) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(4, 3) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(4, 4) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.show()

b. theta1 = np.linspace(0, 2*np.pi, 100) r=1 plt.subplot(2, 2, 1) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 2) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 3) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.subplot(2, 2, 4) plt.plot(r*np.cos(theta1), r*np.sin(theta1)) plt.show()

35) Which is the best way to debug recursive functions? a. Adding print statement of what that line of code does. b. Adding output statements by keeping all the statements left aligned. c. Adding output statements with an indent to print statements at every iteration. d. Adding output statements by keeping all the statements equally indented.

c. Adding output statements with an indent to print statements at every iteration.

26) What is output? def divide_by_two(count): if count == 1: print('Terminated..!') else: print(count) divide_by_two(count/2) divide_by_two(9) a. 9 4.5 2.25 1.125 Terminated..! b. 9 4.5 2.25 Terminated..! c. Infinite loop d. 94.5 2.25 1.125 0.5625 Terminated..!

c. Infinite loop

18) What is output? class Residence: def __init__ (self, addr): self.address = addr def get_residence (self): print (f'Address: {self.address}') class Identity: def __init__ (self, name, age): self.name = name self.age = age def get_Identity (self):print (f'Name: {self.name}, Age: {self.age}') class DrivingLicense (Identity, Residence):def __init__ (self, Id_num, name, age, addr): Identity.__init__ (self,name, age) Residence.__init__ (self,addr) self.License_Id = Id_num def get_details (self):print (f'License No. {self.License_Id}, Name: {self.name}, Age: {self.age}, Address: {self.address}') license = DrivingLicense(180892,'Bob',21,'California') license.get_details()license.get_Identity() a. License No. 180892 Name: Bob, Age: 21 b. License No. 180892, Address: California Name: Bob, Age: 21 c. License No. 180892, Name: Bob, Age: 21, Address: California d. License No. 180892, Name: Bob, Age: 21, Address: California Name: Bob, Age: 21

c. License No. 180892, Name: Bob, Age: 21, Address: California

42) What is the output of the following code if the user enters -1 and 6? def Greater(num1, num2): if (num1 >= num2): print('Number 1 is greater') else: print('Number 2 is greater') def Info(num1, num2): if (num1 < = 0):print('Number 1 cannot be less than or equal to 0...Enter the number again') arg1 = int(input()) arg2 = num2 Info(arg1, arg2) elif (num2 <= 0):print('Number 2 cannot be less than or equal to 0...Enter the number again') arg2 = int(input()) arg1 = num1 Info(arg1, arg2) else: Greater(num1, num2) print('Enter any 2 numbers') user_val1 = int(input()) user_val2 = int(input()) Info(user_val1, user_val2) a. The programs asks the user to enter the second number again. b. The programs asks the user to enter both numbers again c. The programs asks the user to enter the first number again d. Infinite loop

c. The programs asks the user to enter the first number again

56) Complete the code to plot Salary=[5,6,7,8] and Grade=[100,200,300,400]. import numpy as np import matplotlib.pyplot as plt XXX a. plt.plot() plt.show(Salary,Grade) b. plt.plot(Salary,Grade).show() c. plt.plot(Salary,Grade) plt.show() d. plt.show([5,6,7,8],[100,200,300,400]) plt.plot()

c. plt.plot(Salary,Grade) plt.show()

60) Which statement defines a red X marker of size 5 and line width 10 for a line plot? a. plt.plot(X, Y, 'r-', marker='x', linewidth=10, markersize=5) b. plt.plot(X, Y, 'r-X', line_width=10, marker_size=5) c. plt.plot(X, Y, 'rX', linewidth=10, markersize=5) d. plt.plot(X, Y, 'r', marker='X', linewidth=10, markersize=5)

c. plt.plot(X, Y, 'rX', linewidth=10, markersize=5)

63) Identify the correct syntax for text() function to display 'X Y Plot' at the coordinates (x,y) in grey color and font size 12. a. plt.text('X Y Plot', [x,y], color='grey', fontsize=12) b. plt.text((x,y), 'X Y Plot',color='grey', fontsize=12) c. plt.text(x,y, 'X Y Plot', color='grey', fontsize=12) d. plt.text([x,y], 'X Y Plot', color='grey', fontsize=12)

c. plt.text(x,y, 'X Y Plot', color='grey', fontsize=12)

73) The _____ function is used to create a second axis on a plot. a. xaxis() b. axisr() c. twinx() d. axhline()

c. twinx()

32) What is output if the code is executed to search for the letter 'A'? def Find(list, ele, low, high): if high >= low: mid = (high + low)//2 if list[mid] == ele: return mid elif list[mid] > ele: return Find(list, ele, low, mid-1) else: return Find(list, ele, mid + 1, high) else: return -1 listOfLetters = ['B', 'C', 'D', 'E', 'F', 'G', 'H'] result = Find(listOfLetters,'A',0,(len(listOfLetters)-1)) print(result) a. 3 b. Error: The program gets into an infinite loop c. 0 d. -1

d. -1

6) Which statement is not true? a. Inheritance tree describes the hierarchy between base and derived classes. b. A derived class can access the attributes of all of its base classes via normal attribute reference operations. c. A derived class inherits the attributes of the base class, and then adds additional attributes. d. When adding a new derived class, a programmer has to change the base class as well.

d. When adding a new derived class, a programmer has to change the base class as well.

16) Which is an example of inheritance? a. class Library:def __init__(self): self.name = '' class Books: def __init__(self): self.number = '' class Pages: def __init__(self): self.number = '' self.words = '' self.paragraphs = '' b. class Car:def __init__(self): self.type = '' class Boat: def __init__(self): self.model = '' class Engine: def __init__(self): self.model = '' self.type = '' self.power ='' c. class Garden:def __init__(self): self.name = '' class Trees: def __init__(self): self.name = '' self.type = '' self.number = '' d. class Elements:def __init__(self): self.name = '' class Metal(Elements): def __init__(self): Elements.__init__(self) self.mass = '' self.atomicNumber = '' class NonMetal(Elements): def __init__(self): Elements.__init__(self) self.mass = '' self.atomicNumber = ''

d. class Elements:def __init__(self): self.name = '' class Metal(Elements): def __init__(self): Elements.__init__(self) self.mass = '' self.atomicNumber = '' class NonMetal(Elements): def __init__(self): Elements.__init__(self) self.mass = '' self.atomicNumber = ''

47) Which code calculates the power of a number raised to another (a^b)? a. def power(a,b): if b == 1: return a else: return a**power(a,b-1) b. def power(a,b): if b == 1: return a else: return a*power(b-1,a) c. def power(a,b): if b == 1: return a else: return a**power(b-1,a) d. def power(a,b): if b == 1: return a else: return a*power(a,b-1)

d. def power(a,b): if b == 1: return a else: return a*power(a,b-1)

61) Which property is required for plt.legend()? a. alpha b. data c. visible d. label

d. label

33) Which XXX completes the find function? def Find(list, ele, low, high): if high >= low: XXX if list[mid] == ele: return mid elif list[mid] > ele: return Find(list, ele, low, mid-1) else: return Find(list, ele, mid + 1, high) else: return -1 a. mid = low - (high - low) // 2 b.mid = (high - low) // 2 c. mid = (high - low) / 2 d. mid = low + (high - low) // 2

d. mid = low + (high - low) // 2

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

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

57) Which function takes an optional format string argument to specify the color and style of the plotted line? a. plt.show() b. plt.imshow() c. plt.legend() d. plt.plot()

d. plt.plot()

62) Which function is used to add text labels to a plot? a. plt.title() b. plt.xlabel() c. plt.legend() d. plt.text()

d. plt.text()


Conjuntos de estudio relacionados

CH 6 Business Strategy: Differentiation, Cost Leadership and Blue Oceans

View Set