IT 211 -- Quizzes * = correct answer ----------------------------------------------------- Quiz 1 -- Closed Jan 20. 1. Which editor is installed when you install Python on your machine? a. Brackets *b. Idle c. JEdit d. Notepad 2. Which symbol or symbols are placed at the beginning of a line to indicate a Python comment? *a. # b. % c. / d. // 3. Which symbol or symbols are used for the Python integer division operator? a. % b. / *c. // d. \ 4. Which standalone method is used to convert a string to an integer value? *a. int b. parseInt c. to_i d. toInteger 5. What is the output from this Python script? (Check your answer by running the script in IDLE or from a Terminal Window). a = 5 b = 2 a = 2 * a + b + 1 b = a + 3 * b a = a + 3 b = 2 * b print(a, b) a. 13 19 b. 16 16 *c. 16 38 d. 18 42 ----------------------------------------------------- Quiz 2 -- Closed Jan 27. 1. What is the meaning of the + operators in the print statement: name = input("Enter a name: ") print("Hello, " + name + ".") a. addition b. comparison *c. contatenation d. repetition 2. What is the output? s = "abc" print(repr(s)) a. abc b. 'abc' c. "abc" d. 3. What is the Python exponentiation operator? a. # b. ^ c. * *d. ** 4. What is the output? x = 5 if x >= 2: x = x * 2 elif x >= 4: x = x * 3 else: x = x * 5 print(x) *a. 10 b. 15 c.25 d. 35 5. What are the possible outputs? import random n = 2 * random.randrange(0, 2) if n == 0: suit = "club" elif n == 1: suit = "diamond" elif n == 2: suit = "heart" elif n == 3: suit = "spade" print(suit) a. club, diamond *b. club, heart c. club, diamond, heart d. club, diamond, heart, spade ----------------------------------------------------- Quiz 3 -- Closed Feb 3. 1. What is the Python symbol for line continuation? a. / *b. \ c. ; d. _ 2. What is the output? print(bool(0), bool("")) *a. False False b. False True c. True False d. True True 3. What is the output? Recall that if n % 2 == 0, n is even; otherwise n is odd. n = 5 while n > 1: print(n, end=" ") if n % 2 == 0: n = n // 2 else: n = 3 * n + 1 a. No output is printed. *b. 5 16 8 4 2 c. 5 16 8 4 2 1 d. 16 8 4 2 4. Which of the following definite loops has this output? 2 5 8 11 a. for i in range(0, 3): print(2 + 3 * i) b. for i in range(0, 3): print(2 + 3 * i, end=" ") c. for i in range(0, 4): print(2 + 3 * i) *d. for i in range(0, 4): print(2 + 3 * i, end=" ") 5. True or false: the following script contains an infinite loop: n = 1 m = 1 while n < 10: print(m) m = m * 2 *a. True b. False ----------------------------------------------------- Quiz 4 -- Closed Feb 24. 1. What is written to the output file stars.txt? Hint: check your answer by running the script. fout = open("stars.txt", "w") for y in range(0, 2): for x in range(0, 2): fout.write("*") fout.write("\n") fout.close( ) a. **** b. ******** *c. ** d. * ** * * * 2. What happens if you forget to close the file object after you are finished writing to the file? a. An error message is generated. *b. Not all of the output is written to the output file. c. The output is the same as if the file is not closed. d. The output may be written to the wrong output file. 3. The input file values.txt contains these values: 17 31 Which of the following scripts reads values in the input file, computes the sum of the values, then writes the sum to the output file sum.txt? Only one choice has the lines of the script in the correct order. *a. fin = open("values.txt", "r") a = fin.readline( ).strip( ) b = fin.readline( ).strip( ) fin.close( ) sum = int(a) + int(b) fout = open("sum.txt", "w") fout.write(str(sum) + "\n") fout.close( ) b. fin = open("values.txt", "r") fin.close( ) a = fin.readline( ).strip( ) b = fin.readline( ).strip( ) sum = int(a) + int(b) fout = open("sum.txt", "w") fout.close( ) fout.write(str(sum) + "\n") c. a = fin.readline( ).strip( ) b = fin.readline( ).strip( ) fin = open("values.txt", "r") fin.close( ) sum = int(a) + int(b) fout = open("sum.txt", "w") fout.close( ) fout.write(str(sum) + "\n") d. fin = open("values.txt", "r") sum = int(a) + int(b) a = fin.readline( ).strip( ) b = fin.readline( ).strip( ) fin.close( ) fout = open("sum.txt", "w") fout.write(str(sum) + "\n") fout.close( ) 4. Which keyword is used to start the definition of a user defined method? a. def b. function c. method c. sub 5. Which of these is NOT a reason to use methods in software development? a. code reuse b. encapsulation c. modularization d. segmentation ------------------------------------------------------------------ Quiz 5. Closed Mar 3. 1. How many percent signs does this script print? for w in range(0, 50): for y in range(0, 40): for x in range(0, 30): print("%") a. 120 b. 1,200 c. 6,000 *d. 60,000 2. What does PPM mean? a. Paint Pallette Manager b. Pixel Painting Mosaic c. Pixel Pointer Manager *d. Portable Pixel Map 3. What is output? a = ["dog", "cat", "mouse"] a.sort( ) a.reverse( ) print(a) a. ["cat", "dog", "mouse"] b. ["dog", "cat", "mouse"] c. ["mouse", "cat", "dog"] *d. ["mouse", "dog", "cat"] 4. for y in range(0, 11): for x in range(0, 11 - y): print("*", end="") print( ) a. parallelogram b. rectangle c. trapezoid *d. triangle 5. What is the output? f is a user defined method. def f(n): return 3 * x + 2 print(f(5)) a. 5 b. 6 *c. 17 d. 21 ------------------------------------------------------------------ Quiz 6. Closed Mar 10. 1. Which of the following appends the str value "Chicago" to the list a? a. a.add(Chicago) b. add(a, Chicago *c. a.append("Chicago") d. append(Chicago, a) 2. What is the output? a = ["dog", "cat", "mouse"] print("*".join(a)) a. dogcatmouse *b. dog*cat*mouse c. * dog * cat * mouse * d. ['*dog*', '*cat*', '*mouse*'] 3. This script converts a value in miles to inches: value1 = float(input("Input a value in miles: ")) value2 = value1 * 12 * 5280 Which user defined method inputs a value in miles and returns the value in inches? a. def inches_to_miles( ): return value2 b. def inches_to_miles( ): value2 = value1 * 12 * 5280 return value2 *c. def inches_to_miles(the_inches): return the_inches * 12 * 5280 d. def to_miles(the_inches): return value2 4. Which of these builtin datatypes are immutable? a. dict and str b. dict and tuple c. list and str *d. str and tuple 5. Which of these methods creates a new folder? a. create_dir from the os module b. create_folder from the shutil module *c. mkdir from the os module d. make_folder from the shutil module -----------------------------------------------------------------