IT 212 - Quizzes Fall 2020 * = correct answer ----------------------------------------------------- The answers to each quiz will be posted after the quiz closes. Quiz 1 -- Closed Sep 20. 1. How many bits are needed to represent a hex digit? a. 2 *b. 4 c. 6 d. 8 2. Convert 01001011 (binary) to decimal. a. 57 b. 65 * c. 75 d. 415 3. Convert 79 (decimal) to one byte binary. a. 00101001 *b. 00101111 c. 01111001 d. 01111111 4. What is the output? a = "*" b = 12.395 print("{0:s} {1:4.1f} {0:s}".format(a, b)) a. 12.3** *b. *12.4* c. *12.4 d. 12.3* 5. What does this binary ASCII message mean? 01101000 01101111 01110010 01110011 01100101 Convert each byte to hex and look up the letters in the ASCII table. a. apple *b. horse c. paris d. topaz ----------------------------------------------------- Quiz 2 -- Closed Sep 27. 1. What is the output? n = 1 print(bool(n)) a. True b. False c. '0' d. '1' 2. For which choice does the script contain no errors? *a. score = int(input("Enter a course score: ")) if score >= 60: grade = 'Pass' else: grade = 'Fail' print("Grade:", grade) b. score = int(input("Enter a course score: ") if score >= 60: grade = "Pass" else: grade = "Fail" print("Grade:", grade) c. score = int(input("Enter a course score:")) if score >= 60: grade == "Pass" else: grade = "Fail" print("Grade:", grade) d. score = int(input("Enter a course score: ")) if score >= 60: grade = "Pass" else: grade = "Fail" print("Grade:" grade) 3. The square method returns the square of its input. Which statements are in the correct order for defining and testing the square method? *a. def square(n): val = n * n return val x = 25 print(square(x)) b. def square(n): return val val = n * n x = 25 print(square(x)) c. x = 25 print(square(x)) def square(n): val = n * n return val d. def square(n): val = n * n return val print(square(x)) x = 25 4. hr = 13 min = 49 sec = 7 print("{0:02d}:{1:02d}:{2:02d}".format(hr, min, sec)) *a. 13:49:07 b. 13:49:7 c. 13 49 7 d. 13 49 07 5. Which of these methods is not a standalone method? *a. lower b. len c. print d. round ----------------------------------------------------- Quiz 3 -- Closed Oct 4. 1. Which statements are correct for importing and using the method f that takes an int as its parameter? f is contained in the module my_methods.py. *a. import my_methods print(my_methods.f(23)) b. import my_methods from f print(f(23)) c. from f from my_methods print(my_methods.f(23)) d. import my_methods.py print(my_methods.f(23)) 2. If the method f is defined as def f(n): return 2 + n * 3 which assertEqual statement succeeds? a. assertEqual(f(4), 47) b. assertEqual(f(3), 10) c. assertEqual(f(1), 6) *d. assertEqual(f(2), 8) 3. What is the return value of this expression? int(bool("")) *a. 0 b. 1 c. "False" d. True 4. Which is the constructor for the Customer class? *a. Customer b. init c. __init__ d. initialize 5. Which method invokes the dunder method __str__? a. toString b. to_string c. repr *d. str ----------------------------------------------------- Quiz 4 -- Closed Oct 11. Here is the source code for the Friend class with test statements after the class: class Friend: def __init__(self, name): self.name = name def greet(self, other): greeting = "Hello, {0:s}, my name is {1:s}.". \ format(self.name, other.name) return greeting def __str__(self): return self.name f = Friend("Alice") g = Friend("Chloe") print(f.greet(g)) 1. What is the identifier Friend in the source code? a. dunder method b. local variable c. instance method *d. constructor e. parameter f. argument 2. What is the identifier greet in the source code? a. dunder method b. local variable *c. instance method d. constructor e. parameter f. argument 3. What is the identifier __init__ in the source code? *a. dunder method b. local variable c. instance method d. constructor e. parameter f. argument 4. What is the identifier greeting in the source code? a. dunder method *b. local variable c. instance method d. constructor e. parameter f. argument 5. What is the identifier other in the source code? a. dunder method b. local variable c. instance method d. constructor *e. parameter f. argument ----------------------------------------------------- Quiz 5 -- Closed Oct 18. 1. Which dunder method is invoked by this statement? p1 = Person("Alice", "F", 11) a. __str__ b. __lt__ c. __repr__ *d. __init__ e. __eq__ 2. If p is defined by p = Person("Alice", "F", 11) Which dunder method is invoked by this statement? print(p) *a. __str__ b. __eq__ c. __lt__ d. __init__ e. __repr__ 3. If p is defined by p = Person("Alice", "F", 11) Which dunder method is invoked by this statement? s = repr(p) a. __str__ b. __eq__ *c. __repr__ d. __lt__ d. __init__ 4. If p1 and p2 are defined by p1 = Person("Alice", "F", 11) p2 = Person("Bob", "M", 10) Which dunder method is invoked by this statement? print(p1 < p2) a. __eq__ b. __init__ c. __repr__ d. __str__ *e. __lt__ 5. If p1 and p2 are defined by p1 = Person("Alice", "F", 11) p2 = Person("Bob", "M", 10) Which dunder method is invoked by this statement? print(p1 == p2) a. __init__ *b. __eq__ c. __repr__ d. __str__ d. __lt__ ----------------------------------------------------- Quiz 6 -- Closed Oct 25. 1. Which of these assignment statements in a class definition assigns the value 25 to a private instance variable? *a. self._age = 25 b. 25 = _age c. self.age = 25 d. _age = 25 2. Which of these list methods removes an item from a list? a. destroy b. delete c. push *d. pop 3. Which of these is a properly defined __repr__ method? *a. def __repr__(self): return str(self): b. def __repr__( ): return str(self): c. def __repr__( ): return self.__str__( ): d. def __repr__(self): return self.__str__( ): 4. Which Python class header shows that the class MotorBoat inherits from the class Vehicle? a. class Vehicle(MotorBoat): b. class MotorBoat < Vehicle: *c. class MotorBoat(Vehicle): d. class Vehicle : MotorBoat: 5. For what is the super method used? To______________ a. create a new base class. *b. call a method in the base class. c. initialize the instance methods in the derived class. d. create a new derived class. ----------------------------------------------------- Quiz 7 -- Closed Nov. 1 1. If p is a Person object, where the Person class is defined in the Person Example, which of these statements is properly written? a. a = __init__(self) *b. a = Person('Alice', 'F', 11) c. a = Person('Alice', 'F', 11).__init__( ) d. a = __init__('Alice', 'F', 11) 2. If the Person class is defined as in the Person Example, what is the output? a = [ Person("Alice", "F", 11), Person("Bob", "M", 12), \ Person("Cassidy", "F", 8), Person("Ethan", "M", 10) ] print(a[3].name[2]) *a. h b. s c. 2 d. t 3. A dictionary is defined like this: names = {1111 : "Alice"; 2222 : "Bob", 333 : "Chloe"} which statement adds "David" to the dictionary using the key 4444? *a. names[4444] = "David" b. names["David"] = 4444 c. names.put(4444, "David") d. names.append(4444, "David") 4. Which string is accepted by this regular expression? \A\d{3}-\d{2}-\d{4}\Z *a. 123-45-6789 b. 1-2345-6789 c. 12-345-6789 d. 1234-56-789 5. Which method from the re module obtains fields from a string using a regular expression as the delimiter? a. strip *b. split c. find d. search ----------------------------------------------------- Quiz 8 -- Closed Nov. 8 1. ID numbers for a company are of the form E followed by 2 digits, followed by a dash, followed by 4 digits. An example is E87-2236. Which regular expression accepts ID numbers from this company with no additional characters? Match the entire input string, not a substring. a. \AE\d{4}-\d{2}\Z b. Ed{2}\-d{4} *c. \AE\d{2}-\d{4}\Z d. \AEd2-d4\Z 2. The method call re.search(r, s) returns a Match object for the first match with the regular expression r anywhere in the input string s. What is the output from these statements? import re s = 'urtsaacxyz' r = r'[abc]{3}' print(re.search(r, s)) a. None b. *c. d. 3. Which statement returns True if the key k has been entered in the dictionary d? It returns False if the key has not been entered in d. a. d[k] b. d{k} *c. k in d d. k[d] 4. Which statement compiles the Java source code file Greeter.java? a. java Greeter b. java Greeter.java c. javac Greeter.class *d. javac Greeter.java 5. What is the name of the startup method in a Java program? a. startup b. start_up *c. main d. init -----------------------------------------------------