1/71
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
For the binarySearch function in Section 7.9.2, what is low and high after the first iteration of the while loop when invoking binarySearch([1, 4, 6, 8, 10, 15, 20], 11)?
low is 4 and high is 6
If a key is not in the list, the binarySearch function returns _________.
-(insertion point + 1)
If the binary search function returns -4, where should the key be inserted if you wish to insert the key into the list?
at index 3
Use the selectionSort function presented in this section to answer this question. Assume lst is [3.1, 3.1, 2.5, 6.4, 2.1], what is the content of list after the first iteration of the outer loop in the function?
2.1, 3.1, 2.5, 6.4, 3.1
Use the selectionSort function presented in this section to answer this question. What is list1 after executing the following statements? list1 = [3.1, 3.1, 2.5, 6.4] selectionSort(list1)
list1 is 2.5 3.1, 3.1, 6.4
__________ represents an entity in the real world that can be distinctly identified
An object
_______ is a template, blueprint, or contract that defines objects of the same type.
A class
The keyword __________ is required to define a class.
class
An object is an instance of a __________.
class
The constructor creates an object in the memory and invokes __________.
the __Innit__ method
Given the declaration x = Circle(), which of the following statements is most accurate.
x contains a reference to a Circle object.
Analyze the following code:
class A:
def __init__(self, s):
self.s = s
def print(self):
print(s)
a = A("Welcome")
a.print()
The program will be correct if you change print(s) to print(self.s).
Analyze the following code:
class A:
def __init__(self, s = "Welcome"):
self.s = s
def print(self):
print(self.s)
a = A()
a.print()
The program runs fine and prints Welcome
What will be displayed by the following code?
class Count:
def __init__(self, count = 0):
self.count = count
c1 = Count(2)
c2 = Count(2)
print(id(c1) == id(c2), end = " ")
print(c1.count == c2.count)False True
Analyze the following code:
class MyDate:
def __init__(self, year, month, day):
self.year = year
self.month = month
self.day = day
class Name:
def __init__(self, firstName, mi, lastName, birthDate):
self.firstName = firstName
self.mi = mi
self.lastName = lastName
self.birthDate = birthDate
birthDate = MyDate(1990, 1, 1)
name = Name("Ashley", 'F', "Weaver", birthDate)
birthDate = MyDate(1991, 1, 1)
birthDate.year = 1992
print(name.birthDate.year)
The program displays 1990.
What is the value of times displayed?
def main():
myCount = Count()
times = 0
for i in range(0, 100):
increment(myCount, times)
print("myCount.count =", myCount.count, "times =", times)
def increment(c, times):
c.count += 1
times += 1
class Count:
def __init__(self):
self.count = 0count is 100 times is 0
Analyze the following code:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
print(a.x)The program runs fine and prints 1
Analyze the following code:
class A:
def __init__(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
print(a.__y)The program has an error because y is private and cannot be accessed outside of the class.
How do you create a window?
window = Tk()
How do you create an event loop?
window.mainloop()
To create a label under parent window, use _______.
label = Label(window, text = "Welcome to Python")
To create a button under parent window with command processButton, use _______.
Button(window, text = "OK", command = processButton)
How do you create a frame?
frame = Frame()
Assume v1 = IntVar(), how do you set a new value 5 to v1.
v1.set(5)
Assume v1 = IntVar(), how do you create a radio button under parent frame1 with variable bound to v1 and value 1?
Radiobutton(frame1, text = "Yellow", bg = "yellow", variable = v1, value = 1, command = processRadiobutton)
How do you create a GUI component for displaying multiple-lines of text?
use Message
How do you create a text area?
use Text
How do you create a canvas under parent frame1 with background color white and foregroung color green?
Canvas(frame1, bg = "white", fg = "green")
How do you display a text "Good morning" centered at 30, 40 with color red?
canvas.create_text(30, 40, text = "Good morning", fill = "red")
To place a button in a specified row and column in its parent container, use ________.
grid manager
The side option of the pack manager may be _____________.
LEFT, RIGHT, BOTTOM, TOP
Where is linear searching used?
When the list has only a few elements and when it is performing a single search in an unordered list
Which of the following is not a limitation of binary search algorithm?
Binary search algorithm is not efficient when the data elements more than 1500
Which of the following is a disadvantage of linear search?
Greater time complexities compared to other searching algorithms
For a binary search algorithm to work, it is necessary that the array (list) must be
sorted
How does selection sort work?
It repeatedly finds the minimum element and swaps it with the first unsorted element.
What is the main difference between binary search and linear search?
A. Binary search is more efficient than linear search.
B. Binary search requires more memory than linear search
C. Linear search works on unsorted arrays, while binary search does not.
D. Both A and B.
D. Both A and B.
Which of the following is a disadvantage of Selection Sort?
It has a time complexity of O(n^2), which is inefficient for large datasets.
What is the best case scenario for the Selection Sort algorithm?
Selection Sort performs the same regardless of the order of elements.
In Selection Sort, the element being selected is always placed in:
The correct position in the sorted portion.
Which part of the Selection Sort algorithm is responsible for finding the smallest element in the unsorted portion of the list?
The inner loop
How would you access an object's data field name using the dot operator?
object.name
In Python, which of the following refers to an object itself within its own method?
self
Which Python module provides the datetime class used for working with dates and times?
datetime
Which of the following is an example of encapsulation in Python
A.Making all data fields public
B.Using private data fields and methods to control access
C. Inheriting a class to extend functionality
D. Writing multiple functions for a class
B. Using private data fields and methods to control access
Which of the following objects is immutable in Python?
A. Tuple
B. List
C. Set
D. Dictionary
A. tuple
Why is it important to hide data fields in a Python class
To prevent unauthorized access and maintain data integrity
Analyze the following code:
class A:
def __init__(self, s):
self.s = s
def print(self):
print(self.s)
a = A()
a.print()The program has an error because the constructor is invoked without an argument.
In the following code, Which of the following is a private data field?
def A:
def __init__(self):
__a = 1
self.__b = 1
self.__c__ = 1
__d__ = 1
# Other methods omitted__b
Analyze the following code:
class A:
def init(self):
self.x = 1
self.__y = 1
def getY(self):
return self.__y
a = A()
a.__y = 45
print(a.x())The program has an error because y is private and cannot be accessed outside of the class.
Suppose i is 2 and j is 4, i + j is same as _________.
i.__add__(j)
To retrieve the character at index 3 from string s, use _________.
s.getitem(3) and s[3]
To return the length of string s, use _________. Please select all that apply.
s.len() and len(s)
How do you create a root object to access the Tkinter library ?
root = tk.Tk()
How do you create a button?
btn = tk.Button(root, text = 'Click me !',)
To create a label under parent window, use _______.
name_label = tk.Label(root, text='Username')
To define an onclick event for a button, the attribute used is:
command
To get a value from textbox, we use
name = name_entry.get()
Assume v1 =tk.BooleanVar() how do you create a check button with variable bound to v1 with root as the object to Tkinter library
tk.Checkbutton(root, text="2250, variable=v1)
How do you create a password field?
passw_label = tk.Label(root, text='Password')
How do you create a GUI component for displaying message?
Use messagebox
To perform an infinite loop for the window to display output of GUI taking root as the Tkinter object use:
root.mainloop()
checkbutton.pack(padx=40, pady=40) does what?
Places the checkbutton in the window
_______ are geometry managers in Tkinter. (write letters)
A. flow
B. grid
C. pack
D.place
B C D
The side option of the pack manager may be _____________.
A. LEFT
B. RIGHT
C. BOTTOM
D. TOP
A B C D
To create an image, use ______________________.
image = PhotoImage(file = imagefilename)
You can create an image from a ____________ file.
A. .bmp
B. .png
C. .gif
D. .jpg
B and C
You can display an image in ______________.
A. an entry
B. a radio button
C. a check button
D. a button
E. a label
B C D E
How do you display a text "Good morning" centered at 30, 40 with color red?
canvas.create_text(30, 40, text = "Good morning", fill = "red")
How do you draw a polygon consisting of points (30, 40), (50, 50), (10, 100) filled with red color?
canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red")
How do you draw a circle centered at 100, 100 with radius 100 on canvas?
canvas.create_oval(100 - 100, 100 - 100, 100 + 100, 100 + 100)
How do you draw a rectangle centered at 100, 100 with width 100 and height 100 on canvas?
canvas.create_rectangle(100 - 50, 100 - 50, 100 + 50, 100 + 50