INSY 3300 - Final EXAM (T and F and MC) (75 Questions) 100% Correct
INSY 3300 - Final EXAM (T and F and MC) (75 Questions) 100% Correct When working with a sequential access file, you can jump directly to any piece of data in the file without reading the data that comes before it. F When you open a file that file already exists on the disk using the 'w' mode, the contents of the existing file will be erased. T The process of opening a file is only necessary with input files. Output files are automatically opened when data is written to them. F When an input file is opened, its read position is initially set to the first item in the file T When a file that already exists is opened in append mode, the file's existing contents are erased. F If you do not handle an exception, it is ignored by the Python interpreter, and the program continues to execute. F You can have more than one except clause in a try/except statement. T The else suite in a try/except statement executes only if a statement in the try suite raises an exception. F The finally suite in a try/except statement executes only if no exceptions are raised by statements in the try suite. F What will the following code display? try: x = float('abc123') print('The conversion is complete.') except IOError: print('This code caused an IOError.') except ValueError: print('This code caused a ValueError.') print('The end.') This Code caused a Value Error. n The end. What will the following code display? try: x = float('abc123') print(x) except IOError: print('This code caused an IOError.') except ZeroDivisionError: print('This code caused a ZeroDivisionError.') except: print('An error happened.') print('The end.') An error happened. n The end. Lists in Python are immutable. F Tuples in Python are immutable. T The del statement deletes an item at a specified index in a list. T Assume list1 references a list. After the following statement executes, list1 and list2 will reference two identical but separate lists in memory: list2 = list1 F A file object's writelines method automatically writes a newline ('n') after writing each list item to the file. F You can use the + operator to concatenate two lists. T A list can be an element in another list. T You can remove an element from a tuple by calling the tuple's remove method. F What will the following code display? values = [2, 4, 6, 8, 10] print(values[1:3]) 4 6 8 What does the following code display? numbers = [1, 2, 3, 4, 5, 6, 7] print(numbers[5:]) 6 7 What does the following code display? numbers = [1, 2, 3, 4, 5, 6, 7, 8] print(numbers[−4:]) 5 6 7 8 What does the following code display? values = [2] * 5 print(values) 2 2 2 2 2 Once a string is created, it cannot be changed. T You can use the for loop to iterate over the individual characters in a string. T The isupper method converts a string to all uppercase characters. F The repetition operator (*) works with strings as well as with lists. T When you call a string's split method, the method divides the string into two substrings. F What does the following code display? mystr = 'yes' mystr += 'no' mystr += 'yes' print(mystr) yesnoyes What does the following code display? mystr = 'abc' * 3 print(mystr) abcabcabc What will the following code display? mystring = 'abcdefg' print(mystring[2:5]) cde What does the following code display? numbers = [1, 2, 3, 4, 5, 6, 7] print(numbers[4:6]) 5, 6 What does the following code display? name = 'joe' print(()) print(()) print(name) joe n JOE n joe The keys in a dictionary must be mutable objects. F Dictionaries are not sequences. T A tuple can be a dictionary key. T A list can be a dictionary key. F The dictionary method popitem does not raise an exception if it is called on an empty dictionary. F The following statement creates an empty dictionary: mydct = {} T The following statement creates an empty set: myset = () F Sets store their elements in an unordered fashion. T You can store duplicate elements in a set. F The remove method raises an exception if the specified element is not found in the set. T What will the following code display? dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3} print(dct['Tuesday']) 2 What will the following code display? dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3} print(('Monday', 'Not found')) 1 What will the following code display? dct = {'Monday':1, 'Tuesday':2, 'Wednesday':3} print(('Friday', 'Not found')) Not Found What will the following code display? stuff = {'aaa' : 111, 'bbb' : 222, 'ccc' : 333} print(stuff['bbb']) 222 What will the following code display? dct = {1:[0, 1], 2:[2, 3], 3:[4, 5]} print(dct[3]) 4, 5 What values will the following code display? (Don't worry about the order in which they will be displayed.) dct = {1:[0, 1], 2:[2, 3], 3:[4, 5]} for k in dct: print(k) 1, 2, 3 After the following statement executes, what elements will be stored in the myset set? myset = set('a bb ccc dddd') a, b, c, d After the following statement executes, what elements will be stored in the myset set? myset = set([2, 4, 4, 6, 6, 6, 6]) 2, 4, 6 After the following statement executes, what elements will be stored in the myset set? myset = set(['a', 'bb', 'ccc', 'dddd']) ['a', 'bb', 'ccc', 'dddd'] What will the following code display? myset = set('1 2 3') print(len(myset)) 4 After the following code executes, what elements will be members of set3? set1 = set([10, 20, 30, 40]) set2 = set([40, 50, 60]) set3 = (set2) {50, 20, 40, 10, 60, 30} After the following code executes, what elements will be members of set3? set1 = set(['o', 'p', 's', 'v']) set2 = set(['a', 'p', 'r', 's']) set3 = section(set2) p, s After the following code executes, what elements will be members of set3? set1 = set(['d', 'e', 'f']) set2 = set(['a', 'b', 'c', 'd', 'e']) set3 = rence(set2) f After the following code executes, what elements will be members of set3? set1 = set(['d', 'e', 'f']) set2 = set(['a', 'b', 'c', 'd', 'e']) set3 = rence(set1) c, a, b After the following code executes, what elements will be members of set3? set1 = set([1, 2, 3]) set2 = set([2, 3, 4]) set3 = tric_difference(set2) 1, 4 Look at the following code: set1 = set([100, 200, 300, 400, 500]) set2 = set([200, 400, 500]) Which of the sets is a subset of the other? Which of the sets is a superset of the other? set 1 is a superset and set 2 is a subset The practice of procedural programming is centered on the creation of objects. F Object reusability has been a factor in the increased use of object-oriented programming. T It is a common practice in object-oriented programming to make all of a class's data attributes accessible to statements outside the class. F A class method does not have to have a self parameter. F Starting an attribute name with two underscores will hide the attribute from code outside the class. T You cannot directly call the _ _str_ _ method. T One way to find the classes needed for an object-oriented program is to identify all of the verbs in a description of the problem domain. F Polymorphism allows you to write methods in a subclass that have the same name as methods in the superclass T It is not possible to call a superclass's _ _init_ _ method from a subclass's _ _init_ _ method. F A subclass can have a method with the same name as a method in the superclass. T Only the _ _init_ _ method can be overridden. F You cannot use the isinstance function to determine whether an object is an instance of a subclass of a class. F Look at the following class definition. What is the name of the superclass? What is the name of the subclass? class Tiger(Felis): The superclass is Felis The subclass is Tiger Look at the following class definitions: class Plant: def _ _init_ _(self, plant_type): self._ _plant_type = plant_type def message(self): print("I'm a plant.") class Tree(Plant): def _ _init_ _(self): Plant._ _init_ _(self, 'tree') def message(self): print("I'm a tree.") Given these class definitions, what will the following statements display? p = Plant('sapling') t = Tree() ge() ge() I'm a plant. n I'm a Tree.
Written for
- Institution
- INSY 3300
- Course
- INSY 3300
Document information
- Uploaded on
- December 13, 2023
- Number of pages
- 15
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
insy 3300 final exam t and f and mc 75 questi
Also available in package deal