Python

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

0444--Function--What is the max width of the result returned by the following code?: >>> '{:6.2f}'.format(5/ 3)

answer: 6 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0528--Assignment--True or False: Python supports the multiple assignment statement. What is the value of "a" and "b" after the following code executes: a = 6 ; b = 3 a, b = b, a a ==? ; b== ?

answer: a == 3 and b ==6 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 78). Wiley. Kindle Edition.

0043--Operators--Essay: List the Python arithmetic operators

+; -; *; /; **; %; // End Answer E E

0342--What is the output of the following code? a. >>>def greetPerson(*name): b................print('Hello', name) c. greetPerson('Frodo', 'Sauron') z. Choices are below********************** 1. Hello Frodo .....Hello Sauron 2. Hello ('Frodo', 'Sauron') 3. Hello Frodo 4. Syntax Error! greetPerson() can take only one argument.

2. Hello ('Frodo', 'Sauron') - Why are the names returned as a tuple? https://www.programiz.com/node/675/quiz-results/175543/view

0419--Function-- True or False: The function replace(), when invoked on string s, takes two string inputs, old and new, and outputs a copy of string s with every occurrence of substring old replaced by string new.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 96). Wiley. Kindle Edition.

0170--Function--t\f: The return value is the result of a function execution.

Answer: True The result of a function. If a function call is used as an expression, the return value is the value of the expression. (PFE pg 53) End Answer E E

0099--Conditional--t/f: The sequence of statements within a compound statement is referred to as the body.

Answer: True body(PFE pg 39) End Answer E E

0225B--Functions--T\F: The following code will invoke the startswith method: a. >>> line = 'Have a nice day' b. >>> line.startswith('Have') c. Choices are below****************************

Answer: True Some methods such as startswith return boolean values. >>> line = 'Have a nice day' >>> line.startswith('Have') True >>> line.startswith('h') False You will note that startswith requires case to match, so sometimes we take a line and map it all to lowercase before we do any checking using the lower method. (PFE pg 73) End Answer

0487--Text--True or False: If text contains both single quotes and double quotes, then the escape sequence\' or\" is used to indicate that a quote is not the string delimiter but is part of the string value.

Answer: True - excuse = 'I\'m "sick"';print(excuse)-> I'm "sick" Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 93). Wiley. Kindle Edition.

0225C--Functions--T\F: In the following code, "startswith" is invoked on to "line". a. >>> line = 'Have a nice day' b. >>> line.startswith('Have') c. Choices are below****************************

Answer: True - this nomenclature is unclear--review

0147--Function--MultipleChoice: The term ___________ represents the order in which statements are executed. 1. order of operation 2. flow of execution 3. minimax 4. short circuit

Answer: flow of execution Execution always begins at the first statement of the program. Statements are executed one at a time, in order from top to bottom. Function definitions do not alter the flow of execution of the program, but remember that statements inside the function are not executed until the function is called. A function call is like a detour in the flow of execution. Instead of going to the next statement, the flow jumps to the body of the function, executes all the statements there, and then comes back to pick up where it left off. (PFE pg 49) End Answer E E

0285--List--MultipleChoice: How many elements are in the following list? a. ['spam', 1, ['Brie', 'Roquefort', 'Pol le Veq'], [1, 2, 3]] z. Choices are below**************************** 1. ten 2. 2 3. four 4. five

Answer: four Although a list can contain another list, the nested list still counts as a single element. (PFE pg 93) End Answer E E

0030--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "G"? 1. go 2. get 3. global 4. gpu

Answer: global End Answer E E

0242--Files--MultipleChoice--A statement that calls a method. 1. flag 2. invocation 3. counter 4.format string

Answer: invocation (PFE pg 77) End Answer E E

0038--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "R"? 1.rack 2.raise 3.return 4.read 5.repair

Answer: return;raise End Answer E E

0111--Conditional--Essay:When Python is part-way through evaluating a logical expression and stops the evaluation because Python knows the final value for the expression without needing to evaluate the rest of the expression.

Answer: short circuit (PFE pg 40) End Answer E E

0466--OOP--Defined: Container Classes: list, tuple, dictionary, set

Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 254). Wiley. Kindle Edition.

0098--Conditional--Essay: What keyword is associated with "catching an exception"?

The keyword associated with "catching an exception" is "try". End Answer E E

0023--Variable--T/F: The term variable is a __1____ used to refer to __2____. 1. function 2. keyword 3. label or name 4. stored data

keyanswer: 1,'label or name'; 2.,'stored data' >>> v1 = [('1','label or name'), ('2','stored data')] >>> (a1, a2) = v1 >>> print('The term variable is a ' + a1[1] + ' used to refer to '+ a2[1] +'.') v1 = [('1','label or name'), ('2','stored data')] (a1, a2) = v1 print('The term variable is a ' + a1[1] + ' used to refer to '+ a2[1] +'.') End Answer E E

0042--Operators are applied to ______?

operands End Answer E E

0049--Operator--Essay: What will the Modulus operator returns after it executes?

remainder End Answer E E

0110--Error--Essay: A list of the functions that are executing, print a message when an exception occurs.

traceback (PFE pg 40) End Answer E E

0327--Section 10.6 The most common words (PFE pg 123) needs more study

true

0380--Tuple--True or False: the following code will create a tuple: >>> t = 'a', 'b', 'c', 'd', 'e'

true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0083--Conditional--Essay: How many statements can appear in the body or indent code block of an "if" procedure"?

unlimited End Answer E E

0091--Conditional--Essay: How many "elif clauses" are allowed in "chained conditional" statement?

unlimited End Answer E E

0403--Type--True or False (1.) >>> x = int('3.4') >>> x 3 (2.) >>> y = float('3.4') >>> y 3.4 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 39). Wiley. Kindle Edition.

1. False-- >>> x = int('3.4') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '3.4' 2. True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 39). Wiley. Kindle Edition.

0401--Type--True or False 1. >>> x = int(3) >>> x 3 2. >>> x = 3 >>> x 3 3. >>> x = int() >>> x 0 4. >>> y = float() >>> y 0.0 5. >>> s = str() >>> s '' 6. >>> lst = list() >>> lst []

1. True 2. True 3. True 4. True 5. True 6. True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 37). Wiley. Kindle Edition.

0340--What is the output of the following code? a. >>>print(1, 2, 3, 4, sep='*') z. Choices are below********************** 1. 1 2 3 4 2. 1234 3. 1*2*3*4 4. 24

3. 1*2*3*4 https://www.programiz.com/node/720/quiz-results/175483/view

0270--FileWriting--Checkbox: Which statements are true?: 1.To write a file, you have to open it with mode "w" as a second parameter: a. >>> fout = open('output.txt', 'w') 2. If the file already exists, opening it in write mode clears out the old data and starts fresh. 3.If the file doesn't exist, opening it with the write mode will create a new one. 4. if the file does not exist opening it with the write mode will not create a handle. 5. all the above

Answer: 1. True; 2. True; 3. True; 4. False 7.8 Writing files (PFE pg 87) End Answer E E

0116--Function--Essay: What does the function --min('Hello world')-- return?

Answer: ' ' The min function shows us the smallest character (which turns out to be a space). (PFE pg 43) End Answer E E

0260--Files--MultipleChoice--Which statement below best describe what the following code is doing? a.>>> fhand = open('mbox-short.txt') b.>>> inp = fhand.read() z. Choices are below**************************** 1. a. passing a file handle to the variable fhand 2.b. reading the entire file into the variable inp as one string 3.b. is reading one newline delimited record into variable inp 4.a.is assign the actual content of mbox-short.txt to the variable fhand

Answer: (1.) True; (2.) True 7.4 Reading files (PFE pg 82) End Answer E E

0123--Function--MultipleChoice: What value does the function float() return for the argument '3.14159' ? 1. '3' 2. 3.14159 3. 3.0 4. -3 5. 0

Answer: (2.) 3.14159 the function float() converts integers and strings to floating-point numbers (PFE pg 44) End Answer E E

0288--ListMethods--Checkbox: What statements below best describe the code below? : a. >>> t = ['a', 'b', 'c'] b. >>> t.append('d') c. >>> print(t) z. Choices are below**************************** 1. the pirnt statement will return the list ['a', 'b', 'c', 'd'] 2. statement(b.) invokes the append method using dot notation 3. statement(b.) invokes the append method on list variable (t) 4. all are true

Answer: (4.) all are true 8.6 List methods (PFE pg 94) End Answer E E

0135--Function--MultipleChoice: The module function random.choice() will randomly return an element from a given list. Based on the code below which of the list will process without a traceback? a. random.choice(t) b. Choice are below**************************** 1. t = [1, 3, 2, 5, 7] 2.t = ['red', 'white', 'blue', 'orange', 'black'] 3.t = [True, False, None] 4.t = [dog, cat, bird, cow]

Answer: 1, 2 and 3 will process without a traceback; 4 produces a traceback due to a data type error (PFE pg 47) End Answer E E

0116--Function--Essay: What does the function --len('Hello world')-- return?

Answer: 11 Another very common built-in function is the len function which tells us how many items are in its argument. If the argument to len is a string, it returns the number of characters in the string. (PFE pg 43) End Answer E E

0206--Indices--Essay: Given that fruit is a string, what is the result of fruit[:]?

Answer: Returns the entire string. (PFE pg 69) End Answer E E

0233--Functions--True or False: The input() function(method) removes the trailing newline from user input before passing the input as a string.

Answer: True (https://www.programiz.com/python-programming/methods/built-in/input) End Answer E E

0161--Function--t\f: A function is a named sequence of statements that performs some useful operation. Functions may or may not take arguments and may or may not produce a result.

Answer: True A named sequence of statements that performs some useful operation. Functions may or may not take arguments and may or may not produce a result. (PFE pg 53) End Answer E E

0211E--Indices--True or False: Strings are immutable.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 29). Wiley. Kindle Edition.

0545--OOP GUI--True or False: A widget appears in a GUI window only after it has been packed in its master. This is achieved by invoking, on the widget, the method pack(), the method grid() or the method place(), which we do not go over.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 297). Wiley. Kindle Edition.

0540--OOP GUI--True or False: To display text or pictures inside the window created by the following code, we need to use the "tkinter" widget "Label". a. >>> from tkinter import Tk b. >>> root = Tk() c. >>> root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 292). Wiley. Kindle Edition.

0185--Loop--True or False: The while statement is an indefinite loop because it simply loops until some condition becomes False.

Answer: True (PFE pg 60) End Answer E E

0417--Function--True or False: The string method find()returns the index (of the first character) of the first occurrence of string target; otherwise, it returns -1.

Answer: True -- message.find('top secret') Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 95). Wiley. Kindle Edition.

0289--ListMethods--MultipleChoice: Based on the following code what does statement (d.) return? a.>>> t1 = ['a', 'b', 'c'] b.>>> t2 = ['d', 'e'] c.>>> t1.extend(t2) d.>>> print(t1) z. Choices are below**************************** 1. ['a', 'b', 'c', 'd', 'e'] 2.['a', 'b', 'c', 'd'] 3. ['b', 'c', 'd', 'e'] 4. 'a', 'b', 'c', 'd', 'e'

Answer: ['a', 'b', 'c', 'd', 'e'] 8.6 List methods (PFE pg 94) End Answer E E

0245--Files--MultipleChoice--One of the values in a sequence. 1. item 2. invocation 3. immutable 4.format string

Answer: item - (PFE pg 77) End Answer E E

0002--Tuplw--True or False: A tuple is a sequence data type.

Answer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0351--True or False: The regular expression library "re" must be imported into your program before you can use it.

Answer: true Regular expressions (PFE pg 127) End Answer E E

0310I--Match the word nested list to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

/7. nested list- A list that is an element of another list. 8.15 Glossary (PFE pg 105) End Answer

0344--Recursion--What is the output of the following program? def Foo(x): ....if (x==1): .........return 1 ....else: .........return x+Foo(x-1) print(Foo(4)) 1. 10 2. 24 3. 7 4. 1

1. 10 - tested with interpreter 1st call of x + foo(x-1) --> 4 + Foo(4-1)--2nd call returned 6 for Foo(4-1);4+6=10 2nd call of x + foo(x-1) --> 3 + Foo(3-1)-->3rd call return 3 for Foo(3-1);3+3=6 3rd call of x + foo(x-1) --> 2 + Foo(2-1)--> if argument == 1 return 1; 2 + 1 = 3

0337--Which of the following is correct? 1. Variable name can start with an underscore. 2. Variable name can start with a digit. 3. Keywords cannot be used as a variable name. 4. Variable name can have symbols like: @, #, $ etc.

1. False 2. FALSE 3. TRUE 4. FALSE Variable name can start with an underscore. https://www.programiz.com/node/720/quiz-results/175483/view

0415-Function---True or False: 1. >>> x = eval('input('Enter x: ')') Enter x: 10 >>> x 10 2. >>> x = eval(input('Enter x: ')) Enter x: '10' >>> x '10' 3. >>> x = eval(input('Enter x: ')) Enter x: 10 >>> x 10

1. False - Traceback due to tick marks around ('input('Enter x: ')') 2. True 3. True -The function eval() takes a string as input and evaluates the string as if it were a Python expression. >>> eval('3') 3 >>> eval('3 + 4') 7 >>> eval('len([3, 5, 7, 9])') 4 -The function eval() can be used together with the function input() when we expect the user to type an expression (a number, a list, etc.) when requested. >>> x = input('Enter x: ') Enter x: 10 >>> x '10' >>> x = eval(input('Enter x: ')) Enter x: 'dog' >>> x 'dog' >>> x = eval(input('Enter x: ')) Enter x: '10' >>> x '10' >>> x = eval(input('Enter x: ')) Enter x: 10 >>> x 10 >>> x = eval('input('Enter x: ')') File "<stdin>", line 1 x = eval('input('Enter x: ')') ^ SyntaxError: invalid syntax Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 56). Wiley. Kindle Edition.

0183--Loop--True or FALSE : Based on the following code, choose all that apply: a. while True: b. .....line = input('> ') c. .....if line == 'done': d. ..........break e. .....print(line) f. .print('Done!') g. Choices are below**************************** 1. the condition in the while header will change to False when the value of the variable "line" equal 'done'. 2. the while statement will terminate when the variable "line" equal 'done'. 3. the "break" statement force execution to return to the while header. 4. the "break" statement force execution to the next statement that is outside the body of the while loop -- print('Done!'). 5. the stop condition for this code is expressed affirmatively(stop when this happens). 6. the stop condition for this code is expressed negatively(continue until this happen).

1. False; 2. True; 3. False; 4. True; 5. True; 6. False -- (PFE pg 59) End Answer E E

0402--Boolean--True or False 1. True is converted to 1 before integer addition is executed to give an integer result: >>> True + 5 6 2. Boolean values True and False typically behave like values 1 and 0, respectively, in almost all contexts.

1. True 2. True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 38). Wiley. Kindle Edition.

0373--Socket--True or False: 1. \r\n signifies an EOL (end of line) 2.\r\n\r\n signifies nothing between two EOL sequences 3. \r\n\r\n is the equivalent of a blank line. 4. HTTP protocol require a blank line follow a GET request. 5. To request a document from a web server, a connection is made to the target server on port 80, 6. mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 7. mysock.connect(('data.pr4e.org', 80)) represents the domain--data.pr4e.org-- and the port--80 the method will connect to. 8.One of the requirements for using the HTTP protocol is the need to send and receive data as bytes objects, instead of strings. The encode() and decode() methods convert strings into bytes objects and back again. 9. mysock.send(cmd) 10. data = mysock.recv(512) 11. The end=' ' is just to say that you want a space after the end of the statement instead of a new line character. The end parameter means that the line gets 'space' at the end rather than a newline character. >>>print(data.decode(),end='')

1. True 2. True 3. True 4. True 5. True 6. ???-he does not want to explain this. He thinks it is too complicated. 7. True 8. True 9. ??? 10. ??? 11. true 12.2 The world's simplest web browser (PFE pg 141) End Answer E E

0372--Socket--True or False: 1. A socket is much like a file, except that a single socket provides a two-way connection between two programs. 2. You can both read from and write to the same socket. 3. If you write something to a socket, it is sent to the application at the other end of the socket. 4. If you read from the socket, you are given the data which the other application has sent. 5. The HyperText Transfer Protocol is a set of precise rules that determine who is to go first, what they are to do, and then what the responses are to that message, and who sends next, and so on. 6. Uniform Resource Locators or URLs

1. True 2. True 3. True 4. True 5. True 6. True 12.1 HyperText Transfer Protocol - HTTP (PFE pg 141) End Answer E E

0374--Socket--True or False: 1. The pausing of either the sending application or the receiving application is called "flow control." 2. The Content-Type for image retrieval is "image/jpeg". 3. The Content-Type for text retrieval is "text/plain". 4. The following code opens a port on the host server: import socket import time HOST = 'data.pr4e.org' PORT = 80 mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.connect((HOST, PORT)) 5. The code below uses b'' notation to specify that a variable should be stored(encoded) as a bytes object. The function encode() and b'' are equivalent. mysock.sendall(b'GET http://data.pr4e.org/cover3.jpg HTTP/1.0\r\n\r\n') count = 0 6. The code below returns b'Hello world' >>> b'Hello world' 7. The code below returns b'Hello world' >>> 'Hello world'.encode() 8. The function recv() an argument that determines the maximum number of bytes retrieved from the buffer at one time.

1. True 2. True 3. True 4. True 5. True 6. True 7. True 8. True 12.3 Retrieving an image over HTTP (PFE pg 144) End Answer E E

0375--Continuation--True or False: 1. The following code has a valid line continuation: a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + \ 8 + 9 2. The backslash--"\"-- is the Python line continuation character? 3. Python line continuation is implied inside parentheses ( ), brackets [ ] and braces { }. 4. Following code has the correct Python syntax: a = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) 5. Following code has the correct Python syntax: colors = ['red', 'blue', 'green'] 6. A backslash does not continue a comment. 7. Tokens other than string literals cannot be split across physical lines using a backslash 8. Explicit Python line continuation requires a backslash. 9. Implicit Python line continuation requires a backslash.

1. True - https://www.programiz.com/python-programming/statement-indentation-comments 2. True - https://www.programiz.com/python-programming/statement-indentation-comments 3. True - https://www.programiz.com/python-programming/statement-indentation-comments 4. True - https://www.programiz.com/python-programming/statement-indentation-comments 5. True - https://www.programiz.com/python-programming/statement-indentation-comments 6. True - https://python-reference.readthedocs.io/en/latest/docs/operators/slash.html 7. True - https://python-reference.readthedocs.io/en/latest/docs/operators/slash.html (what is a token?) https://www.programiz.com/python-programming/statement-indentation-comments 8. True - https://stackoverflow.com/questions/4172448/is-it-possible-to-break-a-long-line-to-multiple-lines-in-python 9. False - https://stackoverflow.com/questions/4172448/is-it-possible-to-break-a-long-line-to-multiple-lines-in-python End Answer E E

0375--Continuation--True or False: 1. The following code has a valid line continuation: a = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 2 + 3 + 4 + 5 + 6 + 7 \ 8 + 9 2. The backslash--"\"-- is the Python line continuation character? 3. Python line continuation is implied inside parentheses ( ), brackets [ ] and braces { }. 4. Following code has the correct Python syntax: a = (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) 5. Following code has the correct Python syntax: colors = ['red', 'blue', 'green'] 6. A backslash does not continue a comment. 7. Tokens other than string literals cannot be split across physical lines using a backslash 8. Explicit Python line continuation requires a backslash. 9. Implicit Python line continuation requires a backslash.

1. True - https://www.programiz.com/python-programming/statement-indentation-comments 2. True - https://www.programiz.com/python-programming/statement-indentation-comments 3. True - https://www.programiz.com/python-programming/statement-indentation-comments 4. True - https://www.programiz.com/python-programming/statement-indentation-comments 5. True - https://www.programiz.com/python-programming/statement-indentation-comments 6. True - https://python-reference.readthedocs.io/en/latest/docs/operators/slash.html 7. True - https://python-reference.readthedocs.io/en/latest/docs/operators/slash.html (what is a token?) https://www.programiz.com/python-programming/statement-indentation-comments 8. True - https://stackoverflow.com/questions/4172448/is-it-possible-to-break-a-long-line-to-multiple-lines-in-python 9. False - https://stackoverflow.com/questions/4172448/is-it-possible-to-break-a-long-line-to-multiple-lines-in-python End Answer E E

0055--Variables--t/f: Which of the following is true? 1. Variable names can contain both letters and numbers. 2. Variable names can begin with a number. 3. The underscore character (_) can appear in a variable name. 4. Variable names can begin with an underscore--"_". 5. Only letter, number and underscores are legal elements of variable names.

1. True; 2. False; 3. True; 4. True; 5. True End Answer E E

0339--Which of the following is correct? 1. Variable name can start with an underscore. 2. Variable name can start with a digit. 3. Keywords can be used as a variable name. 4. Variable name can have symbols like: @, #, $ et

1. Variable name can start with an underscore. https://www.programiz.com/node/720/quiz-results/175483/view

0527--Tuple--MultiChoice >>> print(1,000,000) 1. Is the parameter 1,000,000 an integer? 2. How does Python interpret the commas associated to the parameter? 3. What value is produced by statement "A."?

1. Yes; 2. commas that are not enclosed in quotation marks delimit each value in a series of numbers. 3. 1_0_0

0052--Sequenced Data--Multiple Choice: Which properties below describe statement "A."A. >>> print(1,000,000) 1. The statement (A.) parameter, 1,000,000, is an integer 2. Python interprets commas as delimiters for sequential data. 3. Statement (A.) will produce the value "1 0 0".

1. Yes; 2. commas that are not enclosed in quotation marks delimit each value in a series of numbers. 3. 1_0_0 End Answer E E

0058--The execution(interactive or batch script) will return what value to the terminal when the following is presented to the Python interpreter? 1. x 2. x = 1 3. x + 5 4. 5 5. print(x)

1. both interactive and batch: returns a traceback because "x" has not been assigned. 2. neither interactive nor batch: The assignment statement produces no output. 3. interactive 4. interactive 5. both interactive and batch End Answer E E

0087--Conditional--t/f: What statements are true with regard to the following code?: a. if x%2 == 0 : b. .....print('x is even') c. else : d. .....print('x is odd') 1. this code will create a traceback 2. this code is representative of if-then-else logic 3. this code is representative of "Alternative execution" logic 4. this code has only one branch

1. false 2. true 3. true 4. false End Answer E E

0081--Conditional--t/f: For the following code , which statements below are true: a.>>>x=10 b.>>>if x>9: c.>>>.....print('end') d.>>>print("goodbye") 1. "if" is a Python reserved word 2. "if" is a Python keyword 3. The colon ":" marks the end of the "if" statement 4. This code will return a traceback 5. Statement (3.) is and indented code block 6. Statement (2.) is the header statement.

1. true 2. true 3. true 4. false 5. true 6. true >>> x=10 >>> if x>9: ... print('end') ... end >>> print("goodbye") goodbye >>> End Answer E E

0082--Conditional--t\f: For the following, which state are true: a.>>>x=10 b.>>>if x>9: c.>>> pass d.>>>print('end') 1. "if" is a Python reserved word 2. "pass" is a Python keyword 3. The colon ":" marks the end of the "if" header statement 4. This code will return a traceback 5. The statement (c.) is and indented code block

1. true 2. true 3. true 4. false 5. true >>> x=10 >>> if x>9: ... pass ... >>> print('end') end End Answer E E

0079--Conditional--MultipleChoice: For the following, which statements are true: 1.>>>x=10 2.>>>if x>9: 3.>>>print('end') 1. "if" is a Python reserved word 2. "if" is a Python keyword 3. The colon ":" marks the end of the "if" statement 4. This code will return a traceback 5. The statement (3.) is and indented code block

1. true 2. true 3. true 4. true 5. false >>> x=10 >>> if x>9: ... print('end') File "<stdin>", line 2 print('end') ^ IndentationError: expected an indented block End Answer E E

0086--Conditional--True or False: Whicn statements below are true? 1. Alternative execution" refers to conditional processing where one of two outcomes(branches) is executed. 2. Only three statements can appear in the body or indent code block of an "if" procedure.

1. true 2. false - the idented code block can contain an unlimited number of statements End Answer E E

0001--Tuple--True or False: 1. A tuple consists of a number of values separated by commas

1. true - A Tuple is a collection of Python objects separated by commas. In someways a tuple is similar to a list in terms of indexing, nested objects and repetition but a tuple is immutable unlike lists which are mutable. 1. sequence data types - https://docs.python.org/3.3/tutorial/datastructures.html#tuples-and-sequences 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0070--Operator--Essay: Where width = 17 for expressions(c. and d.) below, write the value of the expression and the data type: a. >>>width = 17 b. >>>height = 12.0 c. >>>width//2 d. >>>width/2.0 e. >>>height/3 f. >>>1 + 2 * 5

1.) 8 int 2.) 8.5 float 3.) 4.0 float 4.) 11 int End Answer E E

0057--Expression--MultipleChoice: Which of the following is considered an expression? 1. x 2. 5 3. x + 5

1., 2., 3. -- All of these numbers and indicators are considered Python expressions. A value all by itself is considered an expression, and so is a variable. A combination of a value/ variable and operator is also considered an expression. End Answer E E

0054--Variable--(t/f)Which of the following are legal variable names? 1. _oakley 2. 8oakley 3. assert 4. bbb_ccc_ddd_888_1616_if_lambda_yield_continue 5. more@

1.t; 2.f;3.t;4.t;5.f -2. illegal-variable names can not begin with a number 5. illegal- the special character "@" is not allowed as part of a variable name. End Answer E E

0061--What does statement (3.) return? a.>>> first = 10 b.>>> second = 15 c.>>> print(first+second) d.>>>??

25; the content of first is the integer 10. The content of second is the integer 15. The print() know to add integer; print() knows to concatenate strings. End Answer E E

0348--In Python, for and while loops can have optional else statement? 1. Only for loops can have optional else statement 2. Only while loops can have optional else statement 3. Both loops can have optional else statement 4. Loops cannot have else statement in Python

3. Both loops can have optional else statement. research https://www.programiz.com/node/664/quiz-results/175787/view

0232--Loop--FlowofExecution--MultipleChoice: For the following code, which of the statements are False?: a. while True: b. .....line = input('> ') c. .....if line[0] == '#': #if the first position equals "#" d. ..........continue e. .....if line == 'done': #if line equals 'done' f. ..........break g.......print(line) h. print('Done!') b. Choices are below**************************** 1. User inputs "Hello world!" ; the code returns "Hello world!" 2. User inputs "#" ; the code returns a prompt, ">". 3. User inputs "done"; the code breaks and resumes the loop at the top. 4. the user inputs nothing and press the enter key; the code returns an empty prompt. 5. all the above

3. False -- this statement will terminate the while loop. 4. False -- the user inputs nothing and press the enter key; the code returns an empty prompt. - the code will return a traceback because a null value type is not comparable to a type string. Traceback (most recent call last): File "copytildone.py", line 3, in <module> if line[0] == '#': IndexError: string index out of range (PFE pg 74) Empty strings can be tested for explicitly: if x == '': (https://stackoverflow.com/questions/9914061/how-do-i-check-if-a-user-left-the-input-or-raw-input-prompt-empty) End Answer E E

0347--What is the output of the following code? a. >>>if None: b............ print("Hello") z. Choices are below********************** 1. False 2. Hello 3. Nothing will be printed 4. Syntax error

3. Nothing will be printed - you tested this; is 'None' related to Boolean? https://www.programiz.com/node/664/quiz-results/175787/view

0078--Python has how many keywords\reserved words?

33 End Answer E E

0338--Which of the following is correct? 1. Comments are for programmers for better understanding of the program. 2. Python Interpreter ignores comment. 3. You can write multi-line comments in Python using triple quotes, either ''' or """. 4. All of the above

4. All of the above https://www.programiz.com/node/720/quiz-results/175483/view

0075--Operators--MultipleChoice: Which of the following are not Python comparison operators; 1. x != y # x is not equal to y 2. x > y # x is greater than y 3. x < y # x is less than y 4. x >= y # x is greater than or equal to y 5. x <= y # x is less than or equal to y 6. x is y # x is the same as y 7. x is not y # x is not the same as y 8. x => y # x is greater than or equal to y 9. x =< y # x is less than or equal to y

8. and 9. are not Python comparison operators End Answer E E

0048--Operators--Essay: What are the Python comparison operators?

== -- If the values of two operands are equal, then the condition becomes true. != -- If values of two operands are not equal, then condition becomes true. <> -- If values of two operands are not equal, then condition becomes true. > -- If the value of left operand is greater than the value of right operand, then condition becomes true. < -- If the value of left operand is less than the value of right operand, then condition becomes true. >= -- If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. <= -- If the value of left operand is less than or equal to the value of right operand, then condition becomes true. End Answer E E

0072--Write a program which prompts the user for a Celsius temperature, convert the temperature to Fahrenheit, and print out the converted temperature.

>>> promptCel = input("Enter degrees Celsius: ") >>> intpromptCel= int(promptCel) >>> tempFahr = (intpromptCel * 9/5) + 32 >>> print(tempFahr) End Answer E E

0071--Write a program to prompt the user is prompted as follows for hours and rate per hour to compute gross pay: Enter Hours: 35 Enter Rate: 2.75 Pay: 96.25

>>> promptHrs = input("Enter Hours: ") >>> promptRte = input("Enter Rates: ") >>> intpromptHrs= int(promptHrs) >>> intpromptRte= int(promptRte) >>> payTot = intpromptHrs*intpromptRte End Answer E E

0290--ListMethods--Checkbox: What statements below best describe the code below? : a.>>> t = ['d', 'c', 'e', 'b', 'a'] b.>>> t.sort() c.>>> print(t) d.>>> t = t.sort() e.>>> print(t) z. Choices are below**************************** 1.statement(b.) invokes the sort method on list variable (t) 2. statement(c.) returns ['a', 'b', 'c', 'd', 'e'] 3. statement(e.) returns ['a', 'b', 'c', 'd', 'e'] 4. statement (d.) invokes the void method sort() 5. statement (d.) invokes the sort method on list variable "t" sort the content of "t"; then assign "t" a value of "None" 6. statement(b.) invokes the sort method on list variable "t" which sort the content of "t";

Answer: (1.) true; (2.) true; (3.) false-e. returns "None"; (4.) true; (5.)true; (6.) true >>> t = ['d', 'c', 'e', 'b', 'a'] >>> t.sort() >>> print(t) ['a', 'b', 'c', 'd', 'e'] >>> t = t.sort() >>> print(t) None >>> Most list methods are void; they modify the list and return None.; 8.6 List methods (PFE pg 94) End Answer E E

0298--ListString--Checkbox: Which ones of the following are True?: a. >>> t = ['pining', 'for', 'the', 'fjords'] b. >>> delimiter = ' ' c. >>> delimiter.join(t) z. Choices are below**************************** 1. the join method is the inverse of the split method. 2.the join method will return a concatenation of the elements of a list. 3. the join method takes a list as its argument. 4. the method call ' '.join(['pining', 'for', 'the', 'fjords']) will return 'pining for the fjords' 5. the method call ''.join(['pining', 'for', 'the', 'fjords']) will return 'piningforthefjords' 6. The method call in (4.) above is acting on a different value than the method call in (5.) above.

Answer: 1. True 2. True 3. True 4. False 5. False 6. False >>> >>> join(['pining', 'for', 'the', 'fjords']) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'join' is not defined >>> >>> t = ['pining', 'for', 'the', 'fjords'] >>> delimiter = ' ' >>> delimiter.join(t) 'pining for the fjords' >>> >>> delimiter.join(['pining', 'for', 'the', 'fjords']) 'pining for the fjords' >>> 8.9 Lists and strings (PFE pg 98) End Answer E E

0313--Dictionaries--Checkbox: Which ones of the following are True?: 1. An implementation is a way of performing a computation 2. Dictionaries have a method called get that takes a key and a default value. If the key appears in the dictionary, get() returns the corresponding value; otherwise it returns the default value. For example: a. ..........>>> counts = { 'chuck' : 1 , 'annie' : 42, 'jan': 100} b. ..........>>> print(counts.get('jan', 0)) c. ..........100 d. ..........>>> print(counts.get('tim', 0)) e. ..........0 3.the get() method automatically handles the case where a key is not in a dictionary;it returns zero. 4. The use of the get() method in a counting loop is a very commonly used "idiom" in Python

Answer: 1. True 2. True 3. True 4. True 5. 9.1 Dictionary as a set of counters (PFE pg 109) End Answer E E

0314--Dictionaries--Operator--True or False: 1. counts[word] += 1; is equivalent to: counts[word] = counts[word] + 1.

Answer: 1. true 9.2 Dictionaries and files (PFE pg 110) End Answer E E

0224--Functions--MultipleChoice: Fill in the Word The "stripe" method removes __a.__from the ______b.____ and ____c.______ of _______d.___. 1. removes whitespace 2. removes newlines 3. middle 4. beginning 5. end 6. a string

Answer: (1.) a. whitespace; (4.) b. beginning; (5.) c. end; (6.) d. a string (PFE pg 73) End Answer E E

0208--Indices--MultipleChoice: Given the code below, choose all the statements that are true. a. >>> greeting = 'Hello, world!' b. >>> new_greeting = 'J' + greeting[1:] c. >>> print(new_greeting) d. Choices are below**************************** 1. line (b.) concatenate the first character of the variable "greeting" with the letter "J" 2. line (b.) assigns the concatenated expression to the variable "new_greeting" 3. line (c.) will return a data type of "None" 4. line (c.) will result in an undefined variable Traceback 5. line (b.) concatenates the last twelve characters of the variable "greeting" with the letter "J". 6. line (b.) assigns the concatenated expression to the variable "new_greeting"

Answer: 1. False 1st char of "greeting is "H" 2. True 3. False 4. False 5. True 6. True This example concatenates a new first letter onto a slice of greeting. It has no effect on the original string. >>> greeting = 'Hello, world!' >>> new_greeting = 'J' + greeting[1:] >>> print(new_greeting) Jello, world! (PFE pg 70) End Answer E E

0209--Patterns--MultipleChoice: Based on the code below, which statements are true?: a.>>> x = 1 b.>>> y = 0 c.>>> x >= 2 and y != 0 and (x/y) > 2 d._______?______ e.>>> x = 6 f.>>> y = 0 g.>>> x >= 2 and y != 0 and (x/y) > 2 h.____??_____ i.>>> x >= 2 and (x/y) > 2 and y != 0 j.___???_____ k. Choices are below**************************** 1. statement c. returns False because all the expressions in the statement evaluate to False 2. statement g. returns False because the expressions (x/y) > 2 is undefined. 3. statement g. returns a Traceback because the expressions (x/y) > 2 is undefined. 4. the computation pattern of statement g. is known as a guardian pattern.

Answer: 1. False: Statement c. returns False because the first expression (x>=2) is False. So, based the circuit breaker rule execution stops. 2. False: Statement g. returns False because the expression (y!=0) is False. So, based the circuit breaker rule execution stops. 3. False 4. True In the second expression, we say that y != 0 acts as a guard to insure that we only execute (x/y) if y is non-zero. (PFE pg 39) End Answer E E

0214--Operators--CharacterValue--MultipleChoice: If the variable "word" equals 'peach' which of the statements below will return True? 1. word == 'banana' 2. word < 'banana' 3. word > 'banana' 4 word != 'banana'

Answer: 1. False; 2. False; 3. True; 4. True (PFE pg 71) End Answer E E

0215--Operators--CharacterValue--MultipleChoice: If the variable "word" equals 'Banana' which of the statements below will return True? a. >>> word = 'Banana' b. Choices are below**************************** 1. word == 'banana' 2. word < 'banana' 3. word > 'banana' 4 word != 'banana'

Answer: 1. False; 2. True; 3. False; 4. True Python does not handle uppercase and lowercase letters the same way that people do. All the uppercase letters come before all the lowercase letters, so: "Your word, Pineapple, comes before banana." >>> word = 'banana' >>> word > 'Banana' True >>> word < 'Banana' False >>> A common way to address this problem is to convert strings to a standard format, such as all lowercase, before performing the comparison. Keep that in mind in case you have to defend yourself against a man armed with a Pineapple. (PFE pg 71) End Answer E E

0184--Loop--True or FALSE : Based on the following code, choose all that apply: a. while True: b. ....line = input('> ') c. .....if line[0] == '#': d. ..........continue e. .....if line == 'done': f. ..........break g. ..........print(line) h. print('Done!') i. Choices are below**************************** 1. the condition in the while header will change to False when the value of the variable "line" equal 'done'. 2. the while statement will terminate when the variable "line" equal 'done'. 3. the "break" statement force execution to return to the while header. 4. the "continue" statement force execution to immediately return to the while header. 5. the stop condition for this code is expressed affirmatively(stop when this happens). 6. the stop condition for this code is expressed negatively(continue until this happen).

Answer: 1. False; 2. True; 3. False; 4. True; 5. True; 6. False (PFE pg 59) End Answer E E

0210--Patterns--MultipleChoice: Based on the code below, which statements are true?: a. word = 'banana' b. count = 0 c. for letter in word: d. .....if letter == 'a': e. .....count = count + 1 f. print(count) g. Choices are below**************************** 1. The code display a counter computation pattern. 2. The code display a traversal computation pattern. 3. The function print(count) will never execute. 4. The program will create a traceback

Answer: 1. True -- This program demonstrates another pattern of computation called a counter. The variable count is initialized to 0 and then incremented each time an "a" is found. (PFE pg 70) 2. True -- Often(the) computations start at the beginning, select each character in turn, do something to it, and continue until the end. This pattern of processing is called a traversal. (PFE pg 68) 3. False 4. False End Answer E E

0145--Function--MultipleChoice: Which statements are true with regard to the code below? Choose all that apply. a.repeat_lyrics() b.def print_lyrics(): c. print("I'm a lumberjack, and I'm okay.") d. print('I sleep all night and I work all day.') e.def repeat_lyrics(): f. print_lyrics() g. print_lyrics() h. Choice are below**************************** 1. line a. is a function execution statement 2.line c. is a function definition statement 3. line e. is a function definition statement 4.this code will traceback 5. the function repeat_lyrics() is defined after it will execute 6. all the function in this code will take an argument 7. this code will execute successfully

Answer: 1. true 2. false 3.true 4. true 5. true 6. false 7. false -- this code generates the following traceback: Traceback (most recent call last): File "lyrics2.py", line 3, in <module> repeat_lyrics() NameError: name 'repeat_lyrics' is not defined As you might expect, you have to create a function before you can execute it. In other words, the function definition has to be executed before the first time it is called. (PFE pg 49) End Answer E E

0325--Dictionary--True or False: 1. For the key-value pairs in the list created from dictionary "d", print each key-value pair: a........... >>>for key, val in list(d.items()): b. ..........>>>.....print(val, key) 2. key and val are the iteration variables in the following code: a. ..........>>> for key, val in list(d.items()): 3. two iteration variables are need in the following code because the item method returns a list of tuples, where each tuple is a key-value pair: a. ..........>>> for key, val in list(d.items()): 4. the following code return values based on the hash order of the item in the dictionary: a. ..........>>> for key, val in list(d.items()): 5. d.items() is of the class dict_items 6. list(d.items()) is of the class list 7. the following code will sort in descending order based on the first element in each tuple: a. ..........>>> l = [(10, 'a'), (22, 'c'), (1, 'b')] b. ..........>>> l.sort(reverse=True)

Answer: 1. true 2. true 3. true 4. true - the hash order is no particular order. 5. true 6. true 7. true 10.5 Multiple assignment with dictionaries (PFE pg 122) End Answer E E

0385--Tuple--True or False: the following code will create a tuple: >>> t2 = ('a')

False - 8. false - Without the comma Python treats ('a') as an expression with a string in parentheses that evaluates to a string 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0397--Object--True or False: It is important to note that a variable does not have a type. A variable is just a name. Only the object it refers to has a type.

True - Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 34). Wiley. Kindle Edition. End Answer E E

0148--Function--MultipleChoice: Based on the code choose all the statements that are true: a.def print_twice(bruce): b. print(bruce) c. print(bruce) d. Choice are below**************************** 1. the name bruce on line a. is a parameter name 2. the parameter name are defined when the function is created 3. the statement >>>print_twice('Micheal') will have the name Micheal print twice. 4. the statement >>>print_twice(Sally) will have the name Sally print twice 5.the statement >>>print_twice() will have a blank line print twice 6.the statement >>>print_twice(math.pi) will have pi print twice

Answer: 1. true 2. true 3. true 4.false -- data type error, Sally need s tick marks, 'Sally' 5.false -- statement will traceback if no argument is given 6. true -- (PFE pg 50) End Answer E E

0138--Function--MultipleChoice: Which of the following are true while defining a function definition? Choose all that apply. 1. the name of a new function follows the "def" keyword. 2.letters, numbers and the underscore are legal characters for the function name. 3.the first character of a function name can be a number. 4.You can use a keyword as the name of a function. 5.The first line of the function definition is called the header. 6.the body of the function( that part following the header) has to be indented. 7.The function body can contain any number of statements. 8. in interactive(interpreter mode) end the function definition with a blank line

Answer: 1.true 2.true 3.false 4.false -"You can't use a keyword as the name of a function, and you should avoid having a variable and a function with the same name.--PFE, pg 47" 5.true 6.true 7.true 8. true (PFE pg 47) End Answer E E

Match 0451--Function--Multiple:s.replace(old, new) 1. A copy of string s with the first character capitalized if it is a letter in the alphabet 2. The number of occurrences of substring target in string s 3. The index of the first occurrence of substring target in string s 4. A copy of string s converted to lowercase 5. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 6. A copy of string s in which characters have been replaced using the mapping described by table 7. A list of substrings of strings s, obtained using delimiter string sep; the default delimiter is the blank space 8. A copy of string s with leading and trailing blank spaces removed 9. A copy of string s converted to uppercase

Answer: Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0507--Execution Control--essay: Using the while loop construct, given examples of the sequence, infinite, interactive, and loop-and-a-half loop patterns.

answer: Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 151). Wiley. Kindle Edition.

0282--ListMethods--Checkbox: Based on the following code which statements are true: a. >>> cheeses = ['Cheddar', 'Edam', 'Gouda'] b. >>> numbers = [17, 123] c. >>> empty = [] d. >>> print(cheeses[0]) e. >>> numbers[1] = 5 f. >>> print(numbers) z. Choices are below**************************** 1. Statement (d.) returns "Cheddar" 2. For statement (d.), the expression inside the brackets specifies the index. 3. the statement print(numbers[1]) will return 17 4. the statement print(numbers[0]) will return a string of '17' 5. strings are mutable 6. lists are mutable 7. statement (f.) will return a traceback 8. statement (f.) will return the list [17, 5] 9. a bracket operator on the left side of an assignment, identifies the element in the list that will be assigned. 10. This relationship between list index and list element is referred to as a mapping; each index "maps to" one of the elements in the list. 1.1 reading or writing a list element that does not exist will return an IndexError. 12.the expression "numbers[-1] = 5" will increase the number of elements in the list from two to three. 13. this statement , 'Edam' in cheeses, will return a value of True

Answer: (1.) True; (2.) True; (3.) False; (4.) False(returns integer 17); (5.) False; (6.) True; (7.) False; 8.) True; (9.) True; (10.) True; (11.) True; (12.) False; (13.) True 8.2 Lists are mutable (PFE pg 91) End Answer E E

0345--Suppose you need to print pi constant defined in math module. Which of the following statements can do this task? 1.....>>> print(math.pi) 2....>>> print(pi) 3...>>> from math import pi .....>>> print(pi) 4...>>> from math import pi .....>>> print(math.pi)

Answer: (3.) >>>from math import pi >>>print(pi) 3.141592653589793 1. >>> print(math.pi) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'math' is not defined 2. >>> print(pi) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'pi' is not defined 4. >>> from math import pi >>> print(math.pi) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'math' is not defined !!!!instead!!!!! >>> import math >>> print(math.pi) 3.141592653589793 >>> dir(math) ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', ' atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor ', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma ', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc'] https://www.programiz.com/node/675/quiz-results/175543/view

0286--List--Checkbox: What does the execution of statement (d.) and statement (e.) return? choose all the true statements. a.>>> a = [1, 2, 3] b.>>> b = [4, 5, 6] c.>>> c = a + b d.>>> print(c) e.>>> print(a * 4) z. Choices are below**************************** 1. statement (d.) returns [5,7,9] 2. statement (d.) returns [5,6,7,6,7,8,7,8,9] 3. statement (d.) returns [6, 15] 4. statement (d.) returns [1,2,3,4,5,6] 5 statement (d.) returns the concatenation of list variable (a) and list variable (b) 6. statement (e.) returns [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]

Answer: (4.) true; (5.) true; (6.) true 8.4 List operations (PFE pg 93) End Answer E E

0519--Dictionaries--True or False: . This method, pop(), takes a key, and if the key is in the dictionary, it removes the associated (key, value) pair from the dictionary and returns the value: >>> days.pop('Fr') 'Friday' >>> days {'Mo': 'Monday', 'We': 'Wednesday', 'Th': 'Thursday', 'Sa': 'Sat'}

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 170). Wiley. Kindle Edition.

0455--OOP--True or False: Every Python object has its own, separate namespace.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 242). Wiley. Kindle Edition.

0517--Dictionaries--The indexing operator [] cannot be used to get a slice of a dictionary.

answer: true ---This makes sense: A slice implies an order, and there is no order in a dictionary. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 169). Wiley. Kindle Edition.

0283--ListMethods--Checkbox: Based on the following code which statements below are true?: a. >>> numbers = [17, 123] b.>>> for i in range(len(numbers)): c.>>> .....numbers[i] = numbers[i] * 2 z. Choices are below**************************** 1. on line (a.)the list [17, 123] is assigned to the variable numbers 2. the expression len(numbers) on line (b.) will return the number of elements in the variable "numbers". 3. the range() views the return from the len() as the final (stop) element in the variable "numbers". 4. the statement "print(list(range(len(numbers))))" will return the list "[0, 1]" 5. the list(range(n)) will return the list [n, n-1] 6. the index, i = 0, maps to the first element in the variable "numbers", 17 7. the index i = 1 maps to the second element in the variable "numbers", 123 8. all the above

Answer: (1.) true (2.) true - len returns the number of elements in the list. (3.) true - range returns a list of indices from 0 to n − 1, where n is the length of the list. (4.) true - C:\Users\Brad\Desktop\Python\Project\forLength.py (5.) true - C:\Users\Brad\Desktop\Python\Project\forLength.py (6.) true - not certain (7.) true - not certain (8.) all the above - I am not certain about the operation of the range() relative to the for loop index 8.3 Traversing a list Return value from range() : range() returns an immutable sequence object of numbers depending upon the definitions used: range(stop) : - Returns a sequence of numbers starting from 0 to stop - 1 - Returns an empty sequence if stop is negative or 0. (https://www.programiz.com/python-programming/methods/built-in/range) (PFE pg 92) End Answer E E

0264--Functions--MultipleChoice: The rstrip() _________? 1. strips whitespace from the left side of a record. 2. strips whitespace from the right side of a record 3. will strip the white space created by a newline character 4. optionally allows an argument that specifies which trailing characters to remove from the ride side of the record.

Answer: 1. False 2. True - use the rstrip method which strips whitespace from the right side of a string(PFE pg 84) 3. True 4. true - str. rstrip([chars]) chars Optional. String specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix; rather, all combinations of its values are stripped. (https://python-reference.readthedocs.io/en/latest/docs/str/rstrip.html) (PFE pg 84) End Answer E E

0297--ListString--Checkbox: Which ones of the following are True?: 1.A string is a sequence of characters and a list is a sequence of values, but a list of characters is not the same as a string. 2. print(list('spam')) will return 'spam' 3. The split method take an optional argument that allow the programmer to specify the delimiter used to split the elements of a string; otherwise a space is used by default 4. print(split('pining for the fjords')) returns ['pining', 'for', 'the', 'fjords'] 5. the split method requires the use of dot notation

Answer: 1. True 2. False - ['s', 'p', 'a', 'm'] 3. True 4. False - The split method take an optional argument that allow the programmer to specify the delimiter 5.True 8.9 Lists and strings (PFE pg 97) End Answer E E

0024--Which of the following contain "machine code"? 1. The Python interpreter 2. The keyboard 3. Python source file 4. A word processing document

keyanswer: [('1.','True'),('2.','False'),('3.','False'),('4.','False'),] End Answer E E

0062--What does statement (3.) return? 1.>>> first = "10" 2.>>> second = "15" 3.>>> print(first+second) 4.>>>??

"1015"; the content of first is the string 10. The content of second is the string 15. Since these are string data types the print statement knows to concatenate them. End Answer E E

0067--Comment--Essay: What special character indicates the start of a comment?

# End Answer E E

0530--Assignment--True or False: The value of variable "b" in the following equals 6: >>> a=3; b=a; a=6; b == ??

False immutable(interger) >>> a=3; b=a # both a and b refer to the same object >>> a=6 #a is reassigned to a new object >>> b # continues to refer to the original object mutable(list) >>> a = [3, 4, 5]; b = a # both a and b refer to the same object >>> b[1] = 8; #the object that b refers to is modified >>> b [3, 8, 5] #the object that b refers to is modified >>> a [3, 8, 5] #the object that a refers to is also modified Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 77). Wiley. Kindle Edition.

0394--Tuple--True or False: the following code will assign "A" to the first element of the tuple "t": >>> t[0] = 'A'

False - >>> t[0] = 'A' TypeError: object doesn't support item assignment 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0092--Conditional--True or False: All of the "elif" clauses of a "chained conditional" procedure are read before a decision is made to as to which elif clause to execute--if any.

False: Each condition is checked in order. If the first is false, the next is checked, and so on. If one of them is true, the corresponding branch executes, and the statement ends. Even if more than one condition is true, only the first true branch executes. (PFE pg 35) End Answer E E

0371--Regex--Exercise 2: Write a program to look for lines of the form: New Revision: 39772 Extract the number from each of the lines using a regular expression and the findall() method. Compute the average of the numbers and print out the average. Enter file:mbox.txt 38444.0323119 Enter file:mbox-short.txt 39756.9259259

Keyanswer: undone 11.9 Exercises (PFE pg 139) End Answer E E

0094--Conditional--Yes or No: Should the programmer indent the "elif" statements (line c. and e.) in the following?: a. if <condition1>: b. <indented code block 1> c.elif <condition2>: d. <indented code block 2> e.elif <condition3>: f. <indented code block3> g.else: h. <indented code block last> i.<non-indented statement>

No. : The "elif" causes should align with the preceding(associated) "if" statement. End Answer E E

0097--Conditional--What condition will force statement(g.) below to execute? a.inp = input('Enter Fahrenheit Temperature:') b.try: c. .....fahr = float(inp) d. .....cel = (fahr - 32.0) * 5.0 / 9.0 e. .....print(cel) f.except: g. .....print('Please enter a number')

Statement (g.) will execute if statement (c.), (d.) or (e.) fails. : There is a conditional execution structure built into Python to handle these types of expected and unexpected errors called "try / except". The idea of try and except is that you know that some sequence of instruction(s) may have a problem and you want to add some statements to be executed if an error occurs. These extra statements (the except block) are ignored if there is no error.(PFE pg 35) End Answer E E

0063--Operators--Essay: What does statement (d.) return? a.>>> first = 'Test ' b.>>> second = 3 c.>>> print(first * second) d.>>>??

Test Test Test;Note that the procedure adds a space to after each value returned. End Answer E E

0066--What data type will the following code return to the variable "speed" after user input? >>> prompt = 'What...is the airspeed velocity of an unladen swallow?\n' >>> speed = input(prompt)

The input function will return a data type of String. End Answer E E

0077--What does the print() below return? x=10 y=5 print(x>y)

True End Answer E E

0406--OOP--True or False In general, the notation o.m(x,y) means that method m is called on object o with inputs x and y. The method m should be a method belong(in) to the same class as object. Every operation done in Python is a method invocation of this format. This approach to manipulating data, where the data is stored in objects and methods are invoked on objects, is called object-oriented programming (OOP).

True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 40). Wiley. Kindle Edition.

0405--List--True or False: List methods append(), count(), and remove(); To see all the methods supported by the class list, use the help() documentation tool: >>> help(list)

True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 40). Wiley. Kindle Edition.

510--Control Flow--True or False: We may need to perform one action when a condition is true and another if the condition is false. We can achieve this behavior with an if statement, that uses an else clause.

True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 60). Wiley. Kindle Edition.

509--Control Flow--True or False: In a one-way decision if statement, an action is performed only if a condition is true. Then, whether the condition is true or false, execution resumes with the statement following the if statement. In other words, no special action is performed if the condition is false.

True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 60). Wiley. Kindle Edition.

0398--Object--True or False: The Python programming language is said to be object-oriented because values are always stored in objects. In programming languages other than Python, values of certain types are not stored in abstract entities such as objects but explicitly in memory. The term class is used to refer to types whose values are stored in objects. Because every value in Python is stored in an object, every Python type is a class.

True - Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 34). Wiley. Kindle Edition. End Answer E E

0399--Operators--For every operation other than division (/), the following holds: If both operands x and y (or just x for unary operations - and abs()) are integers, the result is an integer. If one of the operands is a float value, the result is a float value. For division (/), the result is a float value, regardless of the operands.

True - Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 36). Wiley. Kindle Edition. End Answer E E

0382--Tuple--True or False: the following code will create a tuple: >>> t =( 'a', )

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0383--Tuple--True or False: the following code will create a tuple: >>> t = 'a',

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0384--Tuple--True or False: the following code will create a tuple: >>> empty_tuple = ()

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0387--Tuple--True or False: the following code will create a tuple: >>> t = tuple('lupins')

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0388--Tuple--True or False: ('l', 'u', 'p', 'i', 'n', 's') is what the following code returns; >>> t = tuple('lupins') >>> print(t)

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0389--Tuple--True or False: Tuple is the name of a constructor

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0390--Tuple--True or False: Tuples are immutable.

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0392--Tuple--True or False: tuple() is a built-in function

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0393--Tuple--True or False: the slice operator in the following code will selects ('b', 'c'): >>> t = ('a', 'b', 'c', 'd', 'e') >>> print(t[1:3])

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0386--Tuple--True or False: the following code will create a tuple: >>> t = tuple()

True - - # An empty tuple >>> empty_tuple = () >>> print (empty_tuple) () 0.1 Tuples are immutable (PFE pg 118) End Answer E E

0396--Object--True or False: Objects are containers for values, integer or other, that hide the complexity of integer (or other) storage and provide the programmer with only the information she needs: the value of the object and what kind of operations can be applied to it.

True - Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 33). Wiley. Kindle Edition. End Answer E E

0228--Overloaded--Operators--True or False: The % operator is used to format string and calculate the remainder related to the division of two numbers.

True - The format operator, % allows us to construct strings, replacing parts of the strings with the data stored in variables. When applied to integers, % is the modulus operator. But when the first operand is a string, % is the format operator.(PFE pg 74) End Answer E E

0529--Assignment--True or False: The value of variable in the following code equals [3,8,5]: a = [3, 4, 5]; b = a b[1] = 8 b == [3, 8, 5] a == [3, 8, 5]

True - Multiple assignments on a "mutable" object. Both "a" and "b" refer to the same list; the assignment b[1] = 8 and the assignment a[-1] = 16 will change the same list, so any change to the list referred by "b" will change the list referred to by a and vice versa. >>> a = [3, 4, 5] >>> b = a >>> b [3, 4, 5] >>> b[1] = 8 >>> b [3, 8, 5] >>> a [3, 8, 5] >>> a[-1] = 16 >>> a [3, 8, 16] >>> b [3, 8, 16] immutable(interger) >>> a=3; b=a # both a and b refer to the same object >>> a=6 #a is reassigned to a new object >>> b # continues to refer to the original object mutable(list) >>> a = [3, 4, 5]; b = a # both a and b refer to the same object >>> b[1] = 8; #the object that b refers to is modified >>> b [3, 8, 5] #the object that b refers to is modified >>> a [3, 8, 5] #the object that a refers to is also modified Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 77). Wiley. Kindle Edition.

0095--Conditional--t\f: "if" statement (a.) contains contains two branches?: a.if x == y: b......print('x and y are equal') c.else: d. ....if x < y: e. ..........print('x is less than y') f. .....else: g. ..........print('x is greater than y')

Two: The outer conditional(1.) contains two branches. The first branch(2.) contains a simple statement. The second branch contains another if statement(4.), which has two branches of its own. Those two branches(5.) and (7.) are both simple statements, although they could have been conditional statements as well.(PFE pg 35) End Answer E E

Yes or No: Is the following assignment legal: i = j = k = 0

Yes - A value can be assigned to several variables simultaneously: >>> i = j = k = 0 The three variables i, j, and k are all set to 0. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 78). Wiley. Kindle Edition.

0085--Conditional--Essay: The following code will produce a traceback?: >>> x = 3 >>> if x < 10: ... .......print('Small') ... ...print('Done')

Yes. When using the Python interpreter, you must leave a blank line at the end of a block, otherwise Python will return an error. A blank line at the end of a block of statements is not necessary when writing and executing a batch script. >>> x = 3 >>> if x < 10: ... print('Small') ... print('Done') File "<stdin>", line 3 print('Done') ^ SyntaxError: invalid syntax >>> x = 3 >>> if x < 10: ... print('Small') ... Small >>> print('Done') Done >>> End Answer E E

0059--Operators--Essay: What value will the following floored expression return? >>> minute = 59 >>> minute//60

Zero. The floored expression truncates the remainder. End Answer E E

0404--Type--Multiple Choice: What is the type of the object that these expressions evaluate to? (a) False + False (b) 2 * 3**2.0 (c) 4// 2 + 4% 2 (d) 2 + 3 == 4 or 5 >= 5 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 40). Wiley. Kindle Edition.

a. int b. float c. int d. Boolean Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 40). Wiley. Kindle Edition.

0400--Operators-- Match a. [expressions...] b. x[], x[index:index] c. ** d. +x, -x e. *,/,//,% f. in, not in, <, <=, >, >=, <>, !=, == g. not x h. and i. or j. +, - z. Choices are below: 1. Product, division, integer division, remainder 2. Comparisons, including membership and identity tests 3. Exponentiation 4. Boolean NOT 5. List definition 6. Boolean AND 7. Boolean OR 8. Positive, negative signs 9. Addition, subtraction 10. Indexing operator

a./5. b./10. c./3. d./8. e./1. f./2. g./4. h./6. i./7. j./9. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 37). Wiley. Kindle Edition.

0378--List--Match a. lst.append(item) b. lst.count(item) c. lst.index(item) d. lst.insert(index, item) e. lst.pop() f. lst.remove(item) g. lst.reverse() h. lst.sort() z. Choices are below********************** 1. Inserts item into list just before index index >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h. 2. Reverses the order of items in the list. >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h. 3. Removes last item in the list. >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h. 4. Returns the index of the first e. occurrence of item in list lst >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h. 5.Adds item to the end of list lst. >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h. 6. Removes first occurrence of item in the list. >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h. 7. Returns the number of occurrences of item in list lst >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h. 8. Sorts the list >>>a. >>>b. >>>c. >>>d. >>>e. >>>f. >>>g. >>>h.

a./5. b./7. c./4. d./1. e./3. f./6. g./2. h./8. (Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 32). Wiley. Kindle Edition.) End Answer E E

0317A--Match the word dictionary to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

a./6. - dictionary - A mapping from a set of keys to their corresponding values. 9.6 Glossary (PFE pg 115) End Answer E E

0056--Keywords--Essay: What are the Python interpret Keywords/Reserve words?

and del from None True as elif global nonlocal try assert else if not while break except import or with class False in pass yield continue finally is raise def for lambda return End Answer E E

0355--Regex--The findall(criteria, string) method searches the string in the second argument and returns a list of all of the strings that look like the search criteria. Which substrings will the following code return? a.>>> \S == non-whitespace b.>>>import re c.>>>s = 'A message from [email protected] to [email protected] about meeting @2PM' d.lst = re.findall('\S+@\S+', s) e.print(lst) z. Choices are below********************** 1. [email protected] 2. [email protected] 3. meeting @2PM 4. all the above

answer: 1. [email protected], 2. [email protected] 11.2 Extracting data using regular expressions (PFE pg 130) End Answer E E

0430--Function--What does the following code return?: >>> '{:8.4}'.format(1000/ 3)

answer: ' 333.3' Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0499--Files--Essay: Based on the code below, what does the statement print(cnt) return? >>> cnt = outfile.write('T') >>> print(cnt)

answer: 1 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 115). Wiley. Kindle Edition.

0433--Match Integer Presentation type d Choices below: 1. Outputs the number in decimal notation (default) 2. Outputs the number in base 16, using lowercase letters for the digits above 9 3. Outputs the number in base 16, using uppercase letters for the digits above 9 4. Outputs the number in binary 5. Outputs the number in base 8 6. Outputs the Unicode character corresponding to the integer value

answer: 1 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0438--Function--match >>> n = 10 >>> '{:c}'.format(n) Choices below: 1. '\n' 2. 'a' 3. '10' 4. '1010'

answer: 1 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0473--Namespace--Multiple(t/f): Given the code below, which of the statements concerning global variable are true?: # module scope2.py a. def f(b): b. ......return a*b c. d. a = 0 e. print('f(3) = {}'.format(f(3))) f. print('a is {}'.format(a)) 1. The variable "a" is defined to the calling program's (module scope2.py) namespace. 2. Variable "a" is global relative to functions called by scope2.py. 3. The execution of (e.) will return 30. 4. Variable "a" is defined to function f() as a local variable. 5. When the function f() executes it will first search for the variable name "a" in the f() namespace. 6. If function f() does not locate variable "a" in its own namespace, it will then search the global namespace scope2.py for the name. 7. The last place function f() will search for a name is in the namespace for builtin modules 8. Function f() uses the value of the global variable "a" on line "b." to compute the f() return value 9. Variable "a" will not be found in the f() namespace when f() executes because "a" has not been defined to the f() namespace. 10. The progressive search of namespace (local, global and builtin) by function f() will find the variable "a" in the global namespace scope2.py. 11. all of the above are true 12. none of the above are true 13. The search for the name "print()" starts in the local namespace(in this case namespace scope2.py), continues through the global namespace(interpreter namespace), and ends, successfully, in the namespace of module builtins.

answer: 1.t;2.t;3.f;4.f;5.t;6.t;7.t;8.t;9.t;10.t;11.f;12.f;13.t Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 213). Wiley. Kindle Edition. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 212). Wiley. Kindle Edition. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 214). Wiley. Kindle Edition.

0512--Dictionaries--Multiple choice: Provide the number of the correct statements: 1. The Python dictionary type, denoted dict, is a container type, just like list and str. 2. A dictionary contains (key, value) pairs. 3. This expression defines a dictionary containing i key:value pairs: {<key 1>:<value 1>, <key 2>:<value 2>,..., <key i>:<value i>} 4. The key and the value are both objects and the key is the "index" that is used to access the value. 5. The (key, value) pairs in a dictionary expression are separated by commas and enclosed in curly braces. 6. The key and value in each (key, value) pair are separated by a colon (:) with the key being to the left and the value to the right of the colon. 7. Keys can be of any type as long as the type is immutable. 8. String and number objects can be keys because they are immutable. 9. Type list cannot be keys because lists are mutable. 10.The value of the dictionary key-value pair can be of any type. 11. all are true

answer: 11. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 167). Wiley. Kindle Edition.

0471--Namespace--Multiple t/f: Pertaining to namespace 9. Names that are local to a function exist only in the namespace associated with the function call. 10. Names that are local to a function are only visible to the code inside the function. 11. Names that are local to a function do not interfere with names defined outside of the function, even if they are the same. 12. Names that are local to a function exist only during the execution of the function; they do not exist before the function starts execution and they no longer exist after the function completes execution. 13. all the above are true 14. all the above are false

answer: 13. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 207). Wiley. Kindle Edition.

0440--Function--multiple choice >>> n = 10 >>> '{:x}'.format(n) Choices below: 1. '\n' 2. 'a' 3. '10' 4. '1010'

answer: 2 -x - Outputs the number in base 16, using lowercase letters for the digits above 9 The type determines how the value should be presented. The available integer presentation types are listed in Table 4.2. We illustrate the different integer type options on integer value 10: >>> n = 10 >>> '{:b}'.format(n) '1010' >>> '{:c}'.format(n) '\n' >>> '{:d}'.format(n) '10' >>> '{:x}'.format(n) 'a' Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0435--Match Integer Presentation type x Choices below: 1. Outputs the number in decimal notation (default) 2. Outputs the number in base 16, using lowercase letters for the digits above 9 3. Outputs the number in base 16, using uppercase letters for the digits above 9 4. Outputs the number in binary 5. Outputs the number in base 8 6. Outputs the Unicode character corresponding to the integer value

answer: 2 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0436--Match Integer Presentation type X Choices below: 1. Outputs the number in decimal notation (default) 2. Outputs the number in base 16, using lowercase letters for the digits above 9 3. Outputs the number in base 16, using uppercase letters for the digits above 9 4. Outputs the number in binary 5. Outputs the number in base 8 6. Outputs the Unicode character corresponding to the integer value

answer: 3 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0439--Function--Match >>> n = 10 >>> '{:d}'.format(n) Choices below: 1. '\n' 2. 'a' 3. '10' 4. '1010'

answer: 3 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0523--Dictionaries--True or False: 1. The method items() returns a container that contains tuple objects, one for each (key, value) pair: >>> days.items() dict_items([('We', 'Wednesday'), ('Mo', 'Monday'), ('Th', 'Thursday'), ('Tu', 'Tuesday')]) 2. This method is typically used to iterate over the (key, value) pairs of the dictionary: >>> for item in days.items(): print(item, end=';') ('Fr', 'Friday'); ('Mo', 'Monday'); ('We', 'Wednesday'); ('Th', 'Thursday'); ('Sa', 'Saturday'); 3. all the above

answer: 3. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 172). Wiley. Kindle Edition.

0464--OOP--Multiple: Choose all that are true 1. When the function __init__ is added to a class, the Python interpreter will be automatically called it whenever an object(new class instance) is created. 2. Below the method __init__() is of the class Point that takes two input arguments. This method definition is a modification of the function __init__() that will allow the function to take two input arguments plus the obligatory argument self a. class Point: b......'represents points in the plane' c. def __init__(self, xcoord, ycoord): d......'initializes point coordinates to (xcoord, ycoord)' e. .....self.x = xcoord f. ......self.y = ycoord g. h. #implementations of methods setx(), sety(), get(), and move() 3. all the above are true 4. none of the above are true

answer: 3. all the above are true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 249). Wiley. Kindle Edition.

0431--Match Integer Presentation type b Choices below: 1. Outputs the number in decimal notation (default) 2. Outputs the number in base 16, using lowercase letters for the digits above 9 3. Outputs the number in base 16, using uppercase letters for the digits above 9 4. Outputs the number in binary 5. Outputs the number in base 8 6. Outputs the Unicode character corresponding to the integer value

answer: 4 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0368--help()--True or False: 1. You can bring up the Python Interpreter interactive help system using help(). 2. If you know the module you want to use, you can get help by importing the module -- for example, import re -- and using "dir" -- dir(re) to return the methods related to that module. 3. the following code will return with some summary documentation related to the regular expression search method: >>> help (re.search) 4. all the above

answer: 4. all the above 11.7 Debugging (PFE pg 138) End Answer E E

0474--Namespace--Multiple(t/f): Given the code below, which of the statements concerning global variable are true?: #scope3.py a. def f(b): b. global a c. a = 6 d. e. a = 0 f. print('f(3) = {}'.format(f(3))) g. print('a is {}'.format(a)) 1. Variable "a" is local to the scopy3.py namespace. 2. Within the function f() namespace, variable "a" is defined as a variable related to the global namespace(namespace for scope3.py) 3. the name "global' is a python keyword 4. a modification to the variable "a" within the namespace of function f() will change the value of the same variable name in namespace scopy3.py. 5. all the above are true 6. none of the above are true

answer: 5. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 214). Wiley. Kindle Edition.

0465--OOP--multiple: based on the code below which statement will instantiate a new Point instance without error?: a. class Point: b. 'represents points in the plane' c. d. def __init__(self, xcoord=0, ycoord=0): e. ....'initializes point coordinates to (xcoord, ycoord)' f. .....self.x = xcoord g. ...self.y = ycoord h. z. choice below; 1. a = Point() 2. a = Point(3,4) 3. a = Point(3) 4. a = Point(,4) 5. all the above are true 6. none of the above are true

answer: 5. -Because the "__init__(self, xcoord=0, ycoord=0)" has the static defaults of zero for argument xcoord and ycoord the instantiation of a Point object will alway default to zero for x or y if the particular argument is not populated. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 250). Wiley. Kindle Edition.

0432--Match Integer Presentation type c Choices below: 1. Outputs the number in decimal notation (default) 2. Outputs the number in base 16, using lowercase letters for the digits above 9 3. Outputs the number in base 16, using uppercase letters for the digits above 9 4. Outputs the number in binary 5. Outputs the number in base 8 6. Outputs the Unicode character corresponding to the integer value

answer: 6

0467--OOP--multiple(t/f): Based on the code below, which statements are true?: a. >>> lst = [3, 4, 5] b. >>> lst c. [3, 4, 5] d. >>> repr(lst) e. '[3, 4, 5]' z. hoices below; 1. The operator repr() is called automatically by the interpreter whenever an object must be represented as a string. 2. The representation displayed at the terminal by the interpreter result from a call on repr(). 3. The interpreter calls str() to returns a representation without tic marks when line (b.) is executed. 4. The explicit execution of repr() while in the shell returns a representation with tic marks when line (d.) is executed. 5. All built-in classes implement overloaded operator repr() for the purpose of displaying objects to the terminal. 6. All the above

answer: 6. -All the above Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 259). Wiley. Kindle Edition. Your code execution: >>> from userRout import Representation >>> rep = Representation() >>> rep canonical string representation >>> print(rep) Pretty string representation.

0521--Dictionaries--True or False: 1. The method keys() returns the keys of the dictionary: >>> keys = days.keys() >>> keys dict_keys(['Fr', 'Mo', 'We', 'Th', 'Sa']) 2. The container object returned by method keys() is not a list. 3. The objects returned by the keys() method are of type <class 'dict_keys'>. 4. The object returned by the keys() method is typically used to iterate over the keys of the dictionary >>> for key in days.keys(): print(key, end='') Fr Mo We Th Sa 5. When we iterate(loop--for key in days:) directly over a dictionary, the Python interpreter translates the statement for key in days to the statement for key in days.keys() before executing it. 6. all the above

answer: 6. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 171). Wiley. Kindle Edition.

0472--Namespace--multiple(t/f): Given the the function f() [outer function] and g() [inner function], which of the following are true when the function f() is executed: a. def g(n): b. .....print('Start g') c. .....h(n-1) d. ....print(n) e. f. def f(n): g. .....print('Start f') h. .....g(n-1) i. .......print(n) j. f(4) 1. the the operating system will store for the function f() its the local variables names(objects) and its next line of of unfinished execution 2. the unfinished execution of the outer function will store in an area of main memory call the program stack 3. the area of the program stack where a specific unfinished function call, in this case f(), is stored is called a stack frame 4. the operating system will place the stack frame for function f() at the top of the program stack 5. when the inner function, g(), completes the operating system will resume execution with stack frame, f(), at the top of the program stack. 6. all the above are true 7. all the above are false

answer: 6. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 209). Wiley. Kindle Edition.

0457--OOP--Multiple: Based on the code below, which of the statements below are true?: a. class Point: b. ....def setx(self, xcoord): c. ........self.x = xcoord z: Choices below; 1. The first input argument of each class method refers to the object the method will be invoked on. 2. The first argument that refers to the Point object invoking method setx() is named "self" rather than point. 3. The name of the first argument of a class method can be anything; the important thing is that the first argument of a class method must refer to the object the method will be invoked on. 4. The name of the first argument of a class method can be anything; the important thing is that the first argument of a class method must refer to the object that is invoking the method. 5. The convention among Python developers is to use name self for the object that the method is invoked on. 6. All the above are true 7. none of the above are true

answer: 6. -The first argument that refers to the Point object invoking method setx() is named self rather than point. The name of the first argument can be anything really; the important thing is that it always refers to the object invoking the method. However, the convention among Python developers is to use name self for the object that the method is invoked on, and we follow that convention. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 243). Wiley. Kindle Edition.

0470--Namespace--Multiple choice: Based on the code which are true?: a. def double(y): b. x = 2 c. print('x = {}, y = {}'.format(x,y)) d. return x*y e. x,y = 20,30 f. print('init shell variable x: ',x) g. print('init shell variable y: ',y) h. print('exec function - function will display its value of x and y to the terminal') i. res = double(4) j. print('shell variable x: ',x) k. print('shell variable y: ',y) l. output: m. init shell variable x: 20 n. init shell variable y: 30 o. exec function - function will display its value of x and p. y to the terminal q. x = 2, y = 4 r. shell variable x: 20 s. shell variable y: 30 1. This code shows that there is areuser defined function variables with the name x and y 2. This code shows that there are variables define on line (e.) that are unrelated to the user defined function. 3. the calling program and the function on line (a.) each will have its own, separate area for execution and names. 4. the areas that separate the execution of the calling program from the execution of the user defined function are called namespaces. 5. Each function call creates a new namespace for the function. 6. Different function calls will have different corresponding namespaces. 7. A separate namespaces prevents interference between the execution of the calling program or other functions. 8. variables defined inside functions are local variables(only for use with that function). 9. all the above

answer: 8 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 205). Wiley. Kindle Edition. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 206). Wiley. Kindle Edition. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 207). Wiley. Kindle Edition.

0463--OOP--multiple(t/f): Choose all the statements below that are true. 1. Variables defined in the namespace of an object are called instance variables. 2. Every instance (object) of a class will have its own namespace and therefore its own separate copy of an instance variable. 3. Unlike class variables, instance variables are defined within methods. 4. Class variables(static variables) are shared by instances of the class. 5. Instance variables are owned by instances of the class. 6. For each object or instance of a class, the instance variables are different. 7. Unlike class variables, instance variables are defined within methods. 8. In the Shark class example below, name and age are instance variables: a.class Shark: b..... def __init__(self, name, age): c......... self.name = name d......... self.age = age 9. all the above are true 10.none of the above are true

answer: 9. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 243). Wiley. Kindle Edition. https://www.digitalocean.com/community/tutorials/understanding-class-and-instance-variables-in-python-3

0429--Function--What does the following code return? >>> '{0:3},{1:5}'.format(12, 354)

answer: >>> ' 12, 354' In this example, we are printing integer values 12 and 354. The format string has a placeholder for 12 with '0:3' inside the braces. The 0 refers to the first argument of the format() function (12), as we've seen before. Everything after the':' specifies the formatting of the value. In this case, 3 indicates that the width of the placeholder should be 3. Since 12 is a two-digit number, an extra blank space is added in front. The placeholder for 354 contains '1:5', so an extra two blank spaces are added in front. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 103). Wiley. Kindle Edition.

0364--Regex--True or False: Remember that the [0-9]+ is "greedy" and it tries to make as large a string of digits as possible before extracting those digits. The regular expression library expands in both directions until it encounters a non-digit, or the beginning or the end of a line. line = 'Details: http://source.sakaiproject.org/viewsvn/?view=rev&rev=39772' re.findall('^Details:.*rev=([0-9.]+)', line)

answer: True 11.3 Combining searching and extracting (PFE pg 134) End Answer E E

0365--Regex--True of False: The regular expression below looks for lines that start with "From" (note the space), followed by any number of characters (.*), followed by a space, followed by two digits([0-9][0-9]), followed by a colon character":". In order to pull out only the hour using findall(), we add parentheses around the two digits. Does this description properly characterize the match and the extract operation in the following code?: a. re.findall('^From .* ([0-9][0-9]):', line) z. Choices are below**********************

answer: True 11.3 Combining searching and extracting (PFE pg 135) End Answer E E

0495--File--true or false: The user defined function numWord(filename) reads an entire file and counts the total number of words it contains: def numWords(filename): .....'returns the number of words in file filename' .....infile = open(filename, 'r') .....content = infile.read() #read the file into a string .....infile.close() .....wordList = content.split() #split file into list of words .....print(wordList) #print list of words too .....return len(wordList)

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 113). Wiley. Kindle Edition.

0502--Execution Control--True or False: The while loop on line 8 below is an accumulator loop pattern that allows the terminal input to accumulate, using the append() method, in a list variable. 1 def cities(): 2 '''returns the list of cities that are interactively entered 3 by the user; the empty string ends the interactive input ''' 4 lst = [] 5 6 city = input('Enter city:') #ask user to enter first city 7 8 while city !='': #if city is not the flag value 9 lst.append(city) #append city to list 10 city = input('Enter city:') #and ask user once again 11 12 return lst

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 148). Wiley. Kindle Edition.

0518--Dictionaries--True or False: The operators + and * are not supported for use on a Python dictionary. Furthermore, the indexing operator [] cannot be used to get a slice of a dictionary. A slice implies an order, and there is no order in a dictionary.

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 169). Wiley. Kindle Edition.

0479--Namespace--True or False:The builtins module contains all the Python built-in types and functions and is usually imported automatically upon starting Python. The module description is accessed with the follwing code: >>>dir(__builtins__) answer: True

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 226). Wiley. Kindle Edition.

0363--Regex--True or False: The regular expression below is looking for lines that start with "Details:", followed by any number of characters (.*), followed by "rev=", and then by one or more digits. The regular express wants to find lines that match the entire expression but it only want to extract the integer number. To accomplish this the bracketed expression --"[0-9]+"-- is surrounded with parentheses. re.findall('^Details:.*rev=([0-9.]+)', line)

answer: True the question is incomplete. we would need to know the content of the character string. 11.3 Combining searching and extracting (PFE pg 134) End Answer E E

0493--File--True or False: Text file formats are platform dependent, and different operating systems use a different byte sequence to encode a new line: • MS Windows uses the \r\n 2-character sequence. • Linux/UNIX and Mac OS X use the \n character. • Mac OS up to version 9 uses the \r character. Python translates platform-dependent line-ends into \n when reading and translates \n back to platform-dependent line-ends when writing. By doing this, Python becomes platform independent.

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 112). Wiley. Kindle Edition.

0477--True or False: The current search path for methods is accessed by executing the code below: >>> import sys >>> sys.path

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 224). Wiley. Kindle Edition.

0462--OOP--True or False:Variables defined in the namespace of an object are called instance variables. Every instance (object) of a class will have its own namespace and therefore its own separate copy of an instance variable.

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 243). Wiley. Kindle Edition.

0461--OOP--True or False: A docstring, is a string that should describe what the function does and must be placed directly below the first line of a function definition. For example: 1 def f(x): 2 .....'returns x**2 + 1' 3 .....res = x**2 + 1 #compute x**2 + 1 and store value in res 4 .....return res #return value of res

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 73). Wiley. Kindle Edition.

0357--Regex--True are False: Remember that the * or + applies to the single character immediately to the left of the plus or asterisk.

answer: True 11.2 Extracting data using regular expressions (PFE pg 131) End Answer E E

0361--Regex--Search for lines that start with 'X' followed by any non whitespace characters and ':' followed by a space and any number. The number can include a decimal. The plus indicates the process should continue to look for the digits 0-9 and ".".Does this description properly characterize the match operation in the following code?: re.findall('^X\S*: ([0-9.]+)', line)

answer: Yes 11.3 Combining searching and extracting (PFE pg 133) End Answer E E

0511--Dictionaries--essay: What does the statement-(b.)- below return? a. >>> employee = { '864-20-9753': ['Anna', 'Karenina'], '987-65-4321': ['Yu', 'Tsun'], '100-01-0010': ['Hans', 'Castorp']} b. >>> employee['987-65-4321']

answer: ['Yu', 'Tsun'] Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 167). Wiley. Kindle Edition.

0369--Regex--match: a. A language for expressing more complex search strings. A regular expression may contain special characters that indicate that a search only matches at the beginning or end of a line or many other similar capabilities. b. Code that works when the input data is in a particular format but is prone to breakage if there is some deviation from the correct format. We call this "brittle code" because it is easily broken. c. The notion that the + and * characters in a regular expression expand outward to match the largest possible string. d. A command available in most Unix systems that searches through text files looking for lines that match regular expressions. The command name stands for "Generalized Regular Expression Parser". e. A special character that matches any character. In regular expressions the wild-card character is the period. z. Choices are below********************** 1. brittle code ..........a. ..........b. ..........c. ..........d. ..........e. 2. greedy matching ..........a. ..........b. ..........c. ..........d. ..........e. 3. grep ..........a. ..........b. ..........c. ..........d. ..........e. 4. regular expression ..........a. ..........b. ..........c. ..........d. ..........e. 5. wild card ..........a. ..........b. ..........c. ..........d. ..........e.

answer: [1./b., 2./c., 3./d., 4./a., 5./e.] 11.8 Glossary (PFE pg 139) End Answer E E

0492--File--match a. infile.read(n) b. infile.read() c. infile.readline() d. infile.readlines() e. outfile.write(s) f. file.close() 1. Read characters from file infile until the end of the file and return characters read as a string 2. Read file infile until the end of the file and return the characters read as a list lines 3. Read file infile until (and including) the new line character or until end of file, whichever is first, and return characters read as a string 4. Close the file 5. Write string s to file outfile 6. Read n characters from the file infile or until the end of the file is reached, and return characters read as a string

answer: a./6.; b./1.; c./3.; d./2.; e./5.; f./4. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 110). Wiley. Kindle Edition.

0500--Files--essay:After this statement "outfile.write(' Still the first line...\n')" executes, where will the cursor point?

answer: first position of the next line Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 115). Wiley. Kindle Edition. "

0332--Which dictionary assignment statement(i. or j.) below will create this traceback; "TypeError: tuple indices must be integers or slices, not str" a. directory[last,first] = number b. cnt = 0 c. last = ('Thomas', 'Miller', 'Harper') d. first = ('Micheal', 'Reggie', 'Brad') e. number = ('215-633-5566', '215-637-7566', '215-634-4566') f. directory = {} g. directory2 = {} h. for name in last: i. ....directory[(last[cnt],first[cnt])] = [number[cnt]] j. ....directory[(last[name],first[name])] = number[name]) k. cnt = cnt + 1

answer: j >>> >>> #directory[last,first] = number ... cnt = 0 >>> last = ('Thomas', 'Miller', 'Harper') >>> first = ('Micheal', 'Reggie', 'Brad') >>> number = ('215-633-5566', '215-637-7566', '215-634-4566') >>> directory = {} >>> directory2 = {} >>> for name in last: ... directory[(last[cnt],first[cnt])] = [number[cnt]] ... # directory[(last[name],first[name])] = number[name]) ... cnt = cnt + 1 ... >>> >>> #directory[last,first] = number ... cnt = 0 >>> last = ('Thomas', 'Miller', 'Harper') >>> first = ('Micheal', 'Reggie', 'Brad') >>> number = ('215-633-5566', '215-637-7566', '215-634-4566') >>> directory = {} >>> directory2 = {} >>> for name in last: ... # directory[(last[cnt],first[cnt])] = [number[cnt]] ... directory[(last[name],first[name])] = number[name] ... cnt = cnt + 1 ... Traceback (most recent call last): File "<stdin>", line 3, in <module> TypeError: tuple indices must be integers or slices, not str >>> C:\Users\Brad\Desktop\Python\Project\loadDict.py

0445--Function--Is argument n+1 in the expression range(2, n+1) represents the start, stop or step argument?:

answer: stop Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 105). Wiley. Kindle Edition. https://pynative.com/python-range-function/

0446--Function--true or false-- The function open() takes three string arguments: a file name and, optionally, a mode and an encoding; infile = open('example.txt', 'r') Choices below:

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 109). Wiley. Kindle Edition.

0489--File--true or false: Python will accept the forward slash/(as opposed to the back slash that Windows normal uses) in pathname of a Windows system.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 109). Wiley. Kindle Edition.

0490--File--true are false: In function call open('example.txt', 'r'), the mode 'r' indicates that the opened file will be read from; it also specifies that the file will be read from as a text file.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 110). Wiley. Kindle Edition.

0491--File--true or false: The difference between opening a file as a text or binary file is that binary files are treated as a sequence of bytes and are not decoded when read or encoded when written to.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 110). Wiley. Kindle Edition.

0494--File--True or false:The user defined function numChar() reads and entire file and count the number of characters the file contains: def numChars(filename): 'returns the number of characters in file filename' infile = open(filename, 'r') content = infile.read() infile.close() return len(content)

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 112). Wiley. Kindle Edition.

0496--File--true or false: The user defined function numLines() reads an entire file and counts the number of lines it contains: 1 def numLines(filename): 'returns the number of lines in file filename' infile = open(filename, 'r') #open the file and read it lineList = infile.readlines() #into a list of lines infile.close() print(lineList) #print list of lines return len(lineList)

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 114). Wiley. Kindle Edition.

0504--Execution Control--True or False: The continue statement does not affect the outer for loop, which will iterate through all the rows of the table regardless of whether the continue statement has been executed. def ignore0(table): '''prints values in 2D list of numbers t as a 2D table; 0 values are no printed''' for row in table: for num in row: #inner for loop if num == 0: #if num is 0, terminate continue #current inner loop iteration and return to "for num in row:" inner loop print(num, end='') #otherwise print num print() #move cursor to next line ---_ - - - - - -

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 150). Wiley. Kindle Edition.

0505--Execution Control--true or false: When the code in a block really doesn't have to do anything, we still have to put some code in that block. Python provides the pass statement, which does nothing but is still a valid statement. The pass statement is used when the Python syntax requires code (bodies of functions and execution control statements). The pass statement is also useful when a code body has not yet been implemented.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 151). Wiley. Kindle Edition.

0506--Execution Control--True or False: The nested loop pattern is particularly useful for processing two-dimensional lists,

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 151). Wiley. Kindle Edition.

0513--Dictionaries--True or false: Because dictionaries can be viewed as a mapping from keys to values, they are often referred to as maps.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 167). Wiley. Kindle Edition.

0514--Dictionaries--t/f: The (key, value) pairs in a Python dictionary are not ordered, and no ordering assumption can be made.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 168). Wiley. Kindle Edition.

0516--Dictionaries--True or False: With regard to Python dictionaries, the in and not in operators are used to check whether an object is a key in the dictionary: >>> 'Fr' in days True >>> 'Su' in days False >>> 'Su' not in days True - - - - - - - -

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 169). Wiley. Kindle Edition.

0520--Dictionaries--True or False: When dictionary days calls method update() with input argument dictionary favorites, all the (key, value) pairs of favorites are added to dictionary days, possibly writing over (key, value) pairs of days: >>> days {'Mo': 'Monday', 'We': 'Wednesday', 'Th': 'Thursday', 'Sa': 'Sat'} >>> favorites = {'Th':'Thursday', 'Fr':'Friday','Sa':'Saturday'} >>> days.update(favorites) >>> days {'Fr': 'Friday', 'Mo': 'Monday', 'We': 'Wednesday', 'Th': 'Thursday', 'Sa': 'Saturday'}

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 170). Wiley. Kindle Edition.

0522--Dictionaries--True or False: The method values() is typically used to iterate over the values of a dictionary: >>> for value in days.values(): print(value, end=',') Friday, Monday, Wednesday, Thursday, Saturday,

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 171). Wiley. Kindle Edition.

0508--Control Flow--True or False: The following code display a multiway if statement: def complete(abbreviation): 'returns day of the week corresponding to abbreviation ' if abbreviation == 'Mo': return 'Monday' elif abbreviation == 'Tu': return 'Tuesday' else: #abbreviation must be Su return 'Sunday'

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 173). Wiley. Kindle Edition.

0453--OOP--True or False: OOP is a software development paradigm that achieves modularity and code portability by organizing application programs around components that are classes and objects.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 239). Wiley. Kindle Edition.

0458--OOP--True or False: We say that the object inherits all the attributes of the class, just as a child inherits attributes from a parent. Therefore, all the attributes of the class are accessible from the namespace of the object.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 244). Wiley. Kindle Edition.

0469--OOP--True or False: The following call will instantiate with a list of values, if values are given: a.class Queue: b....'a classic queue class' c. 'initialize queue based on list q, default is empty d. d. queue' e. def __init__(self, q=None): f. if q == None: g. self.q = [] h. else: i. self.q = q

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 263). Wiley. Kindle Edition.

0336--Functions--True or False: The sort method is only defined for list.

answer: true You can also use the list.sort() method. It modifies the list in-place (and returns None to avoid confusion). Another difference is that the list.sort() method is only defined for lists. In contrast, the sorted() function accepts any iterable. >>> a = [5, 2, 3, 1, 4] >>> a.sort() >>> a [1, 2, 3, 4, 5] https://docs.python.org/3/howto/sorting.html

0488--File--true or false: The relative pathname of a file is the sequence of directories that must be traversed, starting from the current working directory, to get to the file.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 108). Wiley. Kindle Edition.

0524--Dictionaries--True or False: The following code is a substitute implementation of a multiway condition(if-elif-else): def complete(abbreviation): 'returns day of the week corresponding to abbreviation ' days = {'Mo': 'Monday', 'Tu':'Tuesday', 'We': 'Wednesday', 'Th': 'Thursday', 'Fr': 'Friday', 'Sa': 'Saturday', 'Su':'Sunday'} return days[abbreviation]

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 173). Wiley. Kindle Edition.

0475--Namespace--True or False:Once a module is imported, the Python built-in function dir() can be used to view all the module's attributes.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 223). Wiley. Kindle Edition.

0476--Namespace--True or False: The word "math" in the expression below refers to a namespace and the entire expression( math.pi), evaluates the name pi in the namespace math.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 224). Wiley. Kindle Edition.

0480--Namespace--True or False:In a Python application program, one of the modules is special: It contains the "main program" or "top-level module" by which we mean the code that starts the application. The remaining modules are essentially "library" modules that are imported by the top-level module and contain functions and classes that are used by the application. answer:true

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 226). Wiley. Kindle Edition.

0481--Namespace--True or False:If the file is being imported by another module, whether the top-level or other, attribute __name__ is set to the module's name.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 226). Wiley. Kindle Edition.

0482--Namespace--True or False:When a module is imported, the Python interpreter creates a few "bookkeeping" variables in the module namespace.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 226). Wiley. Kindle Edition.

0454--OOP--True or False: A namespace is associated with every Python class, and the name of the namespace is the name of the class.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 241). Wiley. Kindle Edition.

0456--OOP--True or False: The reserved keyword class is used to define a new Python class.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 243). Wiley. Kindle Edition.

0459--OOP--True or False: It is important to understand that methods are defined to the class namespace not to the in namespace of the object. Thus, the Python interpreter will first attempts to find the name of the method in the namespace of the object(the object the method is intended to be invoked on). If the method name does not exist in the namespace of the object, then Python attempts to find the method in the namespace of the class.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 245). Wiley. Kindle Edition

0367--Regex--Match: ˆ Matches the beginning of the line. $ Matches the end of the line. . Matches any character (a wildcard). \s Matches a whitespace character. \S Matches a non-whitespace character (opposite of \s). * Applies to the immediately preceding character(s) and indicates to match zero or more times. *? Applies to the immediately preceding character(s) and indicates to match zero or more times in "non-greedy mode". + Applies to the immediately preceding character(s) and indicates to match one or more times. +? Applies to the immediately preceding character(s) and indicates to match one or more times in "non-greedy mode". 11.6. BONUS SECTION FOR UNIX / LINUX USERS 137 ? Applies to the immediately preceding character(s) and indicates to match zero or one time. ?? Applies to the immediately preceding character(s) and indicates to match zero or one time in "non-greedy mode". [aeiou] Matches a single character as long as that character is in the specified set. In this example, it would match "a", "e", "i", "o", or "u", but no other characters. [a-z0-9] You can specify ranges of characters using the minus sign. This example is a single character that must be a lowercase letter or a digit. [ˆA-Za-z] When the first character in the set notation is a caret, it inverts the logic. This example matches a single character that is anything other than an uppercase or lowercase letter. ( ) When parentheses are added to a regular expression, they are ignored for the purpose of matching, but allow you to extract a particular subset of the matched string rather than the whole string when using findall(). \b Matches the empty string, but only at the start or end of a word. \B Matches the empty string, but not at the start or end of a word. \d Matches any decimal digit; equivalent to the set [0-9]. \D Matches any non-digit character; equivalent to the set [ˆ0-9].

answer: undone 11.5 Summary (PFE pg 136) End Answer E E

0526--Dictionaries--exercise: Implement function lookup() that implements a phone book lookup application. Your function takes, as input, a dictionary representing a phone book. In the dictionary, tuples containing first and last names of individual (the keys) are mapped to strings containing phone numbers (the values). Here is an example: >>> phonebook = {('Anna','Karenina'):'(123)456-78-90', ('Yu', 'Tsun'):'(901)234-56-78', ('Hans', 'Castorp'):'(321)908-76-54'} Your function should provide a simple user interface through which a user can enter the first and last name of an individual and obtain the phone number assigned to that individual. >>> lookup(phonebook) Enter the first name: Anna Enter the last name: Karenina (123)456-78-90 Enter the first name: Yu Enter the last name: Tsun (901)234-56-78

answer: undone Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 177). Wiley. Kindle Edition.

0447--Function--yes or no : Will the open () allow the full pathname as the filename(first argument): exmpltxt = 'C:/Users/lperkovic/example.txt' infile = open('exmptxt', 'r') Choices below:

answer: yes Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 109). Wiley. Kindle Edition.

0460--OOP--True or False: Class attributes can be class methods or class variables. A class variable is one whose name is defined in the namespace of the class.

answer:True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 245). Wiley. Kindle Edition.

0310B--Match the word delimiter to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

b./1. delimiter- A character or string used to indicate where a string should be split. 8.15 Glossary (PFE pg 105) End Answer

0317B--Match the word hashtable to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

b./10. - hashtable - The algorithm used to implement Python dictionaries. 9.6 Glossary (PFE pg 115) End Answer

0310C--Match the word element to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

c./6. element- One of the values in a list (or other sequence); also called items. 8.15 Glossary (PFE pg 105) End Answer

0103--Operators--MultipleChoice: Which of the following symbols are comparison operator? 1. == 2. != 3. > 4. < 5. >= 6. <= 7. =>

comparison operator (PFE pg 40) End Answer E E

0310D--Match the word equivalent to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

d./8. equivalent- Having the same value. 8.15 Glossary (PFE pg 105) End Answer

0317E--Match the word implementation to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

e./8. - implementation - A way of performing a computation. 9.6 Glossary (PFE pg 115) End Answer

0069--Comment--Essay: What delimits a comment?

end of the line End Answer E E

0317F--Match the word item to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

f./ 1. - item - Another name for a key-value pair. 9.6 Glossary (PFE pg 115) End Answer

0310F--Match the word identical to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

f./3. identical- Being the same object (which implies equivalence). 8.15 Glossary (PFE pg 105) End Answer

0239--Files--MultipleChoice--A boolean variable used to indicate whether a condition is true or false. 1. flag 2. empty string 3. counter 4.format string

flag - (PFE pg 77) End Answer E E

0310G--Match the word list to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

g./2. list- A sequence of values. 8.15 Glossary (PFE pg 105) End Answer

0317G--Match the word key to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

g./7. - key - An object that appears in a dictionary as the first part of a key-value pair. 9.6 Glossary (PFE pg 115) End Answer

0107--Conditional--MultipleChoice: A pattern where we construct a logical expression with additional comparisons to take advantage of the short-circuit behavior. 1. comparison operator 2. guardian pattern 3. boolean expression 4. compound pattern

guardian pattern (PFE pg 40) End Answer E E

0317H--Match the word key-value pair to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

h./2. - key-value pair - The representation of the mapping from a key to a value. 9.6 Glossary (PFE pg 115) End Answer

0310H--Match the word list traversal to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

h./5. list traversal- The sequential accessing of each element in a list. 8.15 Glossary (PFE pg 105) End Answer

0317I--Match the word lookup to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

i./11. - lookup - A dictionary operation that takes a key and finds the corresponding value. 9.6 Glossary (PFE pg 115) End Answer

0317J--Match the word nested loops to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

j./5. - nested loops - When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 9.6 Glossary (PFE pg 115) End Answer

0317K--Match the word value to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

k./9. - value - An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 9.6 Glossary (PFE pg 115) End Answer

0014--Tuple-- True or False: () is what the following code returns: >>> t = tuple('lupins');>>> print(t) 1. [lupins] 2. 'lupins' 3. ('lupins') 4. ('l', 'u', 'p', 'i', 'n', 's')

keyanswer: ('l', 'u', 'p', 'i', 'n', 's') 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0019--Mutiple Assignment--Multiple: Statement (c.) returns__1.__ to line (d.) and statement(e.) returns__2__to line (f.): a.>>> m = [ 'have', 'fun' ] b.>>> (x, y) = m c.>>> x d. ??? e.>>> y f. ???

keyanswer: 1. 'have'; 2. 'fun' 10.3 Tuple assignment (PFE pg 120) End Answer E E

0331--Match 1. comparable 2. data structure 3. DSU 4. gather 5. hashable 6. scatter 7. shape (of a data structure) 8. singleton 9. tuple 10. tuple assignment a. Abbreviation of "decorate-sort-undecorate", a pattern that involves building a list of tuples, sorting, and extracting part of the result. b. An immutable sequence of elements. c. A summary of the type, size, and composition of a data structure. d. A type that has a hash function. Immutable types like integers, floats, and strings are hashable; mutable types like lists and dictionaries are not. e. A type where one value can be checked to see if it is greater than, less than, or equal to another value of the same type. Types which are comparable can be put in a list and sorted. f. An assignment with a sequence on the right side and a tuple of variables on the left. The right side is evaluated and then its elements are assigned to the variables on the left. g. The operation of treating a sequence as a list of arguments. h.The operation of assembling a variable-length argument tuple. i. A list (or other sequence) with a single element. j. A collection of related values, often organized in lists, dictionaries, tuples, etc.

keyanswer: 1./e.,2./j.,3./a.,4./d.,5./d.,6./g.,7./c.,8./i.,9./b.,10./f. 10.10 Glossary (PFE pg 125) End Answer E E

0356--Regex--What substrings will the following return? Square brackets are used to indicate a set of multiple acceptable characters used when matching characters in a string. The statement: x = re.findall('[a-zA-Z0-9]\S+@\S+[a-zA-Z]', line) reads as: 1. findall() -- find all the substrings of "line" based on the search criteria 2. '[a-zA-Z0-9]' -- find a substring where the first [the search expression is configure to find one character not multiple characters; this expression seem equivalent to startswith() ] character begins with a lower case alphabet , upper case alphabet or digit zero through nine. 3. \S+ -- if (2.) above is True find the adjacent characters[the ones next to the one found in (2.)] that are non-whitespace up and until the character found is "@" 4. \S+ -- if (3.) above is True find the adjacent characters[the ones following the "@" found in (3.)] that are non-whitespace up and until the last non-whitespace character. 5. '[a-zA-Z0-9]' -- if (3.) above is True find a substring where the last[the search expression is configure to find one character not multiple characters; this expression seem equivalent to endswith() ] character ends with a lower case alphabet , upper case alphabet or digit zero through nine. \S == non-whitespace import re f = ['<[email protected]>', '<[email protected]>', '[email protected]'] for line in f: .....line = line.rstrip() .....x = re.findall('[a-zA-Z0-9]\S+@\S+[a-zA-Z]', line) .....if len(x) > 0: ..........print(x) 1. '[email protected]' 2. '[email protected]' 3. '[email protected]' 4. all the above

keyanswer: 4. all the above 11.2 Extracting data using regular expressions (PFE pg 131) End Answer E E

0022--Boolean--True or False: Expression "(x/y) > 2" in statement (3.) will cause a traceback. 1. >>> x = 6 2. >>> y = 0 3. >>> x >= 2 and y != 0 and (x/y) > 2

keyanswer: False Short-circuiting occurs when (left to right order of operation) one logical expression within in compound logical expressions evaluates to FALSE before the entire compound expression is evaluated. End Answer E E

0021--Boolean--Multiple: What will statement (c.) return? a. >>> x = 6 b. >>> y = 0 c. >>> x >= 2 and (x/y) > 2 and y != 0 1. True 2. False 3. Traceback

keyanswer: Traceback End Answer E E

0330--True or False: We would encounter a composite key if we wanted to create a telephone directory that maps from last-name, first-name pairs to telephone numbers.

keyanswer: True 10.7 Using tuples as keys in dictionariess (PFE pg 124) End Answer E E

0020--Multiple Assignment--Multiple:Statement (d.) returns__1.__ to line (e.) and statement(f.) returns__2__to line (g.): a.>>> m = [ 'have', 'fun' ] b.>>> (x, y) = m c.>>> x, y = y, x d.>>> x e. ??? f.>>> y g. ???

keyanswer: [('1','fun'), ('2','have')] 10.3 Tuple assignment (PFE pg 120) End Answer E E

0024A--Which of the following items are true concerning the characteristics of compilers and interpreters? 1. Compiled source code is converted to machine code. 2. Compiler converted source code(machine code) is stored for future execution. 3. Interpreted source code is converted to machine code. 4. Interpreted converted source code(machine code) executes immediately after conversion. 5. Interpreted converted source code(machine code) is stored for future execution

keyanswer: [('1.','True'), ('2.','True'), ('3.','True'), ('4.','True'), ('5.','False')] Items 1 thru 4 are true: Compiled source code is converted to machine code. The converted code is stored for future execution. Interpreted source code is converted to machine code and executed immediately after conversion. End Answer E E

0008--Tuple--True or False: the following code will create a tuple: >>> t2 = ('a')

keyanswer: false 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0007--Tuple--True or False: the following code will create a tuple: >>> empty_tuple = ()

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0012--Tuple-- True or False: Tuple is the name of a constructor

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0016--Slice--True or False: the slice operator in the following code will selects/return ('b', 'c'): >>> t = ('a', 'b', 'c', 'd', 'e');>>> print(t[1:3])

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0018. True or False: The following code will reassign the content of tuple "t":>>> t = ('a', 'b', 'c', 'd', 'e');>>> t = ('A',) + t[1:]

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

4. True or False: the following code will create a tuple:>>> t =( 'a', 'b', 'c', 'd', 'e')

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0333--Exercise 1: Revise a previous program as follows: Read and parse the "From" lines and pull out the addresses from the line. Count the num- ber of messages from each person using a dictionary. After all the data has been read, print the person with the most commits by creating a list of (count, email) tuples from the dictionary. Then sort the list in reverse order and print out the person who has the most commits. Sample Line: From [email protected] Sat Jan 5 09:14:16 2008 Enter a file name: mbox-short.txt [email protected] 5 Enter a file name: mbox.txt [email protected] 19

keyanswer: undone (PFE pg 126) End Answer E E

0335--Exercise 3: Write a program that reads a file and prints the letters in decreasing order of frequency. Your program should convert all the input to lower case and only count the letters a-z. Your program should not count spaces, digits, punctuation, or anything other than the letters a-z. Find text samples from several different languages and see how letter frequency varies between languages. Compare your results with the tables at https://wikipedia.org/wiki/Letter_frequencies.

keyanswer: undone (PFE pg 126) End Answer E E

0328--Python compares sequences by comparing the first element from each sequence. If they are equal, it goes on to the next element, and so on, until it finds elements that differ. Subsequent elements are not considered (even if they are really big). Given the code below, which element first determines that 't1' is less than 't2'? 1. >>> a = 0 2. >>> b = 1 3. >>> c = 2 4. >>> d = 0 5. >>> e = 3 6. >>> f = 4 7. >>> t1 = (a,b,c) 8. >>> t2 = (d,e, f)

keyanswer; b and e/ element 2 10.2 Comparing tuples (PFE pg 118) End Answer E E

0252--Exercise 5: Take the following Python code that stores a string: str = 'X-DSPAM-Confidence:0.8475' Use find and string slicing to extract the portion of the string after the colon character and then use the float function to convert the extracted string into a floating point number.

not done (PFE pg 77) End Answer E E

0326--undone 1. The method translate() returns a copy of the string in which all characters have been translated using table (constructed with the maketrans() function in the string module), optionally deleting all characters found in the string deletechars. Syntax Following is the syntax for translate() method − str.translate(table[, deletechars]); 2.

o 10.6 The most common words (PFE pg 123) End Answer E E

0377--

o 12.4 Retrieving web pages with urllib End Answer E E

0037--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "P"? 1. prune 2. pack 3. pass 4. pick

pass End Answer E E

0114--Functions--MultipleChoice: The result from the execution of a function is called the________. 1. nested conditional 2. guardian pattern 3. return value 4. compound pattern

return value (PFE pg 43) End Answer E E

0379--Tuple--True or False: a tuple is a sequence data type

true - A Tuple is a collection of Python objects separated by commas. In someways a tuple is similar to a list in terms of indexing, nested objects and repetition but a tuple is immutable unlike lists which are mutable. 1. sequence data types - https://docs.python.org/3.3/tutorial/datastructures.html#tuples-and-sequences 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0306--Exercise 3: Rewrite the guardian code in the above example without two if statements. Instead, use a compound logical expression using the and logical operator with a single if statement.

undone 8.14 Debugging (PFE pg 102) End Answer E E

0307--Exercise 4: Download a copy of the file www.py4e.com/code3/romeo.txt. Write a program to open the file romeo.txt and read it line by line. For each line, split the line into a list of words using the split function. For each word, check to see if the word is already in a list. If the word is not in the list, add it to the list. When the program completes, sort and print the resulting words in alphabetical order. Enter file: romeo.txt ['Arise', 'But', 'It', 'Juliet', 'Who', 'already', 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'window', 'with', 'yonder']

undone 8.16 Exercises (PFE pg 105) End Answer E E

0308--Exercise 5: Write a program to read through the mail box data and when you find line that starts with "From", you will split the line into words using the split function. We are interested in who sent the message, which is the second word on the From line. From [email protected] Sat Jan 5 09:14:16 2008 You will parse the From line and print out the second word for each From line, then you will also count the number of From (not From:) lines and print out a count at the end. This is a good sample output with a few lines removed: python fromcount.py Enter a file name: mbox-short.txt [email protected] [email protected] [email protected] [...some output removed...] [email protected] [email protected] [email protected] [email protected] There were 27 lines in the file with From as the first word

undone 8.16 Exercises (PFE pg 106) End Answer E E

0309--Exercise 6: Rewrite the program that prompts the user for a list of numbers and prints out the maximum and minimum of the numbers at the end when the user enters "done". Write the program to store the numbers the user enters in a list and use the max() and min() functions to compute the maximum and minimum numbers after the loop completes. Enter a number: 6 Enter a number: 2 Enter a number: 9 Enter a number: 3 Enter a number: 5 Enter a number: done Maximum: 9.0 Minimum: 2.

undone 8.16 Exercises (PFE pg 106) End Answer E E

0312--Exercise 1: Download a copy of the file www.py4e.com/code3/words.txt Write a program that reads the words in words.txt and stores them as keys in a dictionary. It doesn't matter what the values are. Then you can use the in operator as a fast way to check whether a string is in the dictionary.

undone Dictionaries (PFE pg 108) End Answer E E

0279--Exercise 2: Write a program to prompt for a file name, and then read through the file and look for lines of the form: X-DSPAM-Confidence: 0.8475 When you encounter a line that starts with "X-DSPAM-Confidence:" pull apart the line to extract the floating-point number on the line. Count these lines and then compute the total of the spam confidence values from these lines. When you reach the end of the file, print out the average spam confidence. Enter the file name: mbox.txt Average spam confidence: 0.894128046745 Enter the file name: mbox-short.txt Average spam confidence: 0.750718518519 Test your file on the mbox.txt and mbox-short.txt files.

undone 7.11 Exercises (PFE pg 90) End Answer E E

0280--Exercise 3: Sometimes when programmers get bored or want to have a bit of fun, they add a harmless Easter Egg to their program Modify the program that prompts the user for the file name so that it prints a funny message when the user types in the exact file name "na na boo boo". The program should behave normally for all other files which exist and don't exist. Here is a sample execution of the program: python egg.py Enter the file name: mbox.txt There were 1797 subject lines in mbox.txt python egg.py Enter the file name: missing.tyxt File cannot be opened: missing.tyxt python egg.py Enter the file name: na na boo boo NA NA BOO BOO TO YOU - You have been punk'd! We are not encouraging you to put Easter Eggs in your programs; this is just an exercise.

undone 7.11 Exercises (PFE pg 90) End Answer E E

0304--Debug----Checkbox: Which ones of the following are True?: 1. most list methods modify the argument and return None. 2. The statement t = t.sort() will sort the content of "t" and assign it "t". 3. The following code return the number 3: a. ..........>>>s = "python rocks" b. ..........>>>print(s.count("o") + s.count("p")) 4. The following code returns 'yyyyy': a. ..........>>>s = "python rocks" b. ..........>>>print(s[1] * s.index("n")) 5. Based on the following code "t" is identical to "orig2"; a. ..........>>>t = [1, 2, 3] b. ..........>>>orig2 = t[:] 6. Based on the following code "t" is identical to "orig2"; a. ..........>>>t = [1, 2, 3]; b. ..........>>orig2 = t 7. Based on the following code,line (c.) returns [1,2,3,1]; a. ..........>>>t = [1, 2, 3] b. ..........>>>t.append([1]) c. ..........>>>print(t) 8. Based on the following code, t = [1, 2, 3] line (c.) returns [1,2,3,1] a. ..........>>>t = [1, 2, 3] b. ..........>>>t.append([1]) c. ..........>>>print(t) 9. Based on the following code, t = [1, 2, 3] line (c.) returns [1,2,3,1] a. ..........>>>t = [1, 2, 3] b. ..........>>>t + [ 1] c. ..........>>>print(t) 10. Based on the following code, line (c.) returns [1,2,3,1] a. ..........>>>t = [1, 2, 3] b. ..........>>>t = t + 1 c. ..........>>>print(t) 11. the sorted() method returns a sorted list from the given iterable, but does not alter the related iterable.

Answer: 1. true 2. false - sort() is a void method; it returns 'None' So, assigning the return from the sort to the list would overwrite the list with "None". 3. true - http://interactivepython.org/runestone/static/CS152f17/Strings/StringMethods.html 4. true - http://interactivepython.org/runestone/static/CS152f17/Strings/StringMethods.html 5: false - >>> t = [1, 2, 3];>>> orig2 = t[ :];>>> t is orig2; False 6 true - t = [1, 2, 3];orig2 = t; orig2 is t;True 7. false - t = [1, 2, 3]; t.append([1]); print(t); [1, 2, 3, [1]] 8. false - t = [1, 2, 3]; t = t.append(1); print(t), "print(t)" returns "None" 9. false - t = [1, 2, 3]; t + [1] ; print(t), "print(t)" returns [1,2,3] - see PFE pg 102 10. false - Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list 11. true - (https://www.programiz.com/python-programming/methods/built-in/sorted) 8.14 Debugging (PFE pg 102) End Answer E E

0296--ListFunction--Checkbox: Which ones of the following are True?: 1. The max() works with lists of strings and other types that can be comparable. 2. The len() works with lists of strings and other types that can be comparable. 3. max(iterable, *iterables[, key, default]) represents a syntax definition for the max function. 4.max(arg1, arg2, *args[, key]) represents a syntax definition for the max function. 5. the argument referred to as "key" is an optional built-in or user defined function that will do an initial evaluation of arg1, arg2 and arg*

Answer: 1. true 2. true 3. true 4. true (https://www.programiz.com/python-programming/methods/built-in/max) 8.8 Lists and functions (PFE pg 96) End Answer E E

0301--Aliasing--Checkbox: Which ones of the following are True?: 1. The association of a variable with an object is called a reference 2. An object with more than one reference has more than one name. 3. An aliased object has more than one reference and it has more than one name. 4. modifications to an aliased mutable object will impact all the aliases referencing that object. 5. statement (e.) below will return the list [1, 2, 3] a...........>>> a = [1, 2, 3] b...........>>> b = a c...........>>> if b is a: d...........>>> .....b[0] = 17 e...........>>> print(a)

Answer: 1. true 2. true 3. true 4. true 5. False ---statement (e.) prints [17, 2, 3] 8.12 Aliasing (PFE pg 100) End Answer E E

0311--Dictionary--Checkbox: Which ones of the following are True?: 1. in a dictionary, the indices can be (almost) any type. 2. a dictionary is a mapping between a set of indices (which are called keys) and a set of values. Each key maps to a value. The association of a key and a value is called a key-value pair or sometimes an item. 3.The function dict , dict(), creates a new dictionary with no items. 4.curly brackets, {}, represent an empty dictionary. 5. add items to a dictionary, using square brackets: a. ..........>>> eng2sp['one'] = 'uno' 6. based on the following code statement (d.) returns "{'one': 'uno'} x. ..........>>> eng2sp = {} a. ..........>>> print(eng2sp) b. ...............{} c. ..........>>> eng2sp['one'] = 'uno' d. ..........>>> print(eng2sp) 7. In general, the order of items in a dictionary is unpredictable. 8. the elements of a dictionary are never indexed with integer indices. Instead, you use the keys to look up the corresponding values: 9. the following code creates an exception because the key is not in the dictionary: a. ..........>>> eng2sp = {'one': 'uno', 'two': 'dos', 'three': 'tres'} b. ..........>>> print(eng2sp) c. ..........{'one': 'uno', 'three': 'tres', 'two': 'dos'} d. ..........>>> print(eng2sp['four']) e. ..........KeyError: 'four' 10.when executed against a dictionary the len() returns the number of key-value pairs. 11.when executed against a dictionary the "in" operator validates the existence of a key in the dictionary as True or False. 12. the values method returns the values of a dictionary as a list: vals = list(eng2sp.values()) 13.The code below returns <class 'dict'>: a. ..........>>> eng2sp = {} b. ..........>>> type(eng2sp) .

Answer: 1. true 2. true 3. true 4. true 5. true 6. true 7. true 8. true 9. true 10. true 11. true 12. true 13. true Dictionaries (PFE pg 107) End Answer E E

0300--Objects--Checkbox: Which ones of the following are True?: 1. To check whether two variables refer to the same object, you can use the 'is' operator 2. two different variable names can refer to the same object. 3.two different variable name can store the same value but the value may have come from two different objects. 4. the following code indicates that a and b point to the same object: a. >>> a = 'banana' b. >>> b = 'banana' c. >>> a is b d. >>>True 5. the following code indicates that a and b point to different objects: a. >>> a = [1, 2, 3] b. >>> b = [1, 2, 3] c. >>> a is b d. >>>False 6. Based on question (5.), list a is equivalent to list b. 7. Based on question (5.), list a is not identical to list b. 8. the expression a = [1,2,3], refers to a list object whose value is a particular sequence of elements. 9. two identical objects are also equivalent 10. two equivalent objects are not necessarily identical. 11. Based on question (5.), list a has the same value as list b.

Answer: 1. true 2. true 3. true 4. true 5. true 6. true 7. true 8. true 9. true 10. true 11. true 8.11 Objects and values (PFE pg 99) End Answer E E

0302--List--Checkbox: Which ones of the following are True?: 1. When a list is passed as a function's argument, the function create a reference to the list. 2. The print statement in the following code will return [ 'b', 'c']. a. ..........>>>def delete_head(t): b. ..........>>>.....del t[0] c. ..........>>> letters = ['a', 'b', 'c'] d. ..........>>> delete_head(letters) e. ..........>>> print(letters) 3. Based on the code in question (2.) above, the parameter t and the variable letters are aliases for the same object. 4.Append is a void method that modifies a list and return a value of "None". 5. The following code will create a new list: a. ..........>>> t1 = [1, 2] b. ..........>>> t3 = t1 + [3] c. ..........>>> print(t3) d. ..........[1, 2, 3]

Answer: 1. true 2. true 3. true 4. true - >>> t1 = [1, 2]; >>> t2 = t1.append(3); >>> print(t1); [1, 2,3]; >>> print(t2); None 5. true 8.13 List arguments (PFE pg 100) End Answer E E

0295--ListFunction--Checkbox: Which ones of the following are True? 1. The sum() function only works when the list elements are numbers. 2. The expression print(sum(list((1, 3, 4, 7, 8, 9)))) will return the sum of 1,3,4,7,8 and 9 3. iterable refers to a list, tuple dict or other data structures. Normally, items of the iterable(when using sum()) should be numbers. 4. sum(iterable, start) represents the syntax definition for the sum function. 5. the expression print(sum(0, (1, 3, 4, 7, 8, 9))) will return 32 6. the expression print(sum((1, 3, 4, 7, 8, 9))) = 32 7. the sum() can take two arguments. 8. The following expression will return a list with elements of [1,2,3]; L = list(1,2,3)

Answer: 1. true 2.true - 3. true - (https://www.programiz.com/python-programming/methods/built-in/sum) 4. true - (https://www.programiz.com/python-programming/methods/built-in/sum) 5.false - the first argument of the function must be an iterable. In this case the first argument is a single integer-0 >>> print(sum(0, (1, 3, 4, 7, 8, 9))) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not iterable >>> (https://www.programiz.com/python-programming/methods/built-in/sum) 6. true - >>> print(sum((1, 3, 4, 7, 8, 9))) 32 7. true 8. false - the list() will only take one argument. if the one argument is a list, then, the list must be enclosed in it own parenthesis >>> >>> L = list(1,2,3) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list expected at most 1 arguments, got 3 >>> L = list((1,2,3)) >>> print(L) [1, 2, 3] >>> (https://www.programiz.com/python-programming/methods/built-in/list) 8.8 Lists and functions (PFE pg 96) End Answer E E

0262--Files--MultipleChoice--Which statement below best describe what the following code is doing? a. fhand = open('mbox-short.txt') b. count = 0 c. for line in fhand: d. .....if line.startswith('From:'): e. ..........print(line) z. Choices are below**************************** 1. the variable fhand store the file handle for the file mbox-short.txt 2. the variable fhand store the entire content of the file mbox-short.txt. 3. the variable count counts the number of records in the mbox-short.txt. 4. the index variable line is defined the newline characters in the file mbox-short.txt.

Answer: 1. true; (PFE pg 80) 2. false; (PFE pg 80) 3. false; The count variable has no purpose in this code. 4. true - 7.4 Reading files (PFE pg 80-83) End Answer E E

0216--Oblects--MultipleChoice: An object contains both __a.___ (the actual string itself) and ___b._____, which are effectively functions that are built into the object and are available to any instance of the object. 1. data 2. methods 3. compiler 4. interpreter 5. none of the above

Answer: An object contains both (a.) data (the actual string itself) and (b.)methods, which are effectively functions that are built into the object and are available to any instance of the object. (PFE pg 71) End Answer E E

0266--FlowofExecution--MultipleChoice--What statement(s) best describe line (d.) ; (e.) of the following code?: a.>>>fhand = open('mbox-short.txt') b.>>>for line in fhand: c.>>>..... line = line.rstrip() d.>>> .....if not line.startswith('From:'): e.>>> ..........continue f.>>> .......print(line) z. Choices are below**************************** 1. (d.) if the start of record is not "From:" continue to the next record if (d.) is true 2. (d.) if the start of the record is equal to "From continue to the top of the for loop if (d.) is true 3. none of the above

Answer: True - 1. (d.) if the start of record is not "From:" True - 2. (e.) continue to the top of the for loop if (d.) is true (PFE pg 84) End Answer E E

0267--Functions--MultipleChoice: The find string method __________ 1. finds lines where the search string is anywhere in the target string 2.returns the position of the search string or -1 if the search string is not found 3. stops searching after the first occurrence is found. 4.return 0 if the search string is not found 5. all the above

Answer: True - 1. finds lines where the search string is anywhere in the target string True - 2.returns the position of the search string or -1 if the search string is not found True - 3. stops searching after the first occurrence is found. -- The find() method returns an integer value. If substring exists inside the string, it returns the index of first occurence of the substring. If substring doesn't exist inside the string, it returns -1.(https://www.programiz.com/python-programming/methods/string/find) (PFE pg 85) End Answer E E

0310A--Match the word aliasing to its definition: a. aliasing 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

Answer: a./10. aliasing- A circumstance where two or more variables refer to the same object. 8.15 Glossary (PFE pg 105) End Answer E E

0427--Function--What will the following code return?: hour = 45 minute = 11 second = 33 '{2}:{0}:{1}'.format(hour, minute, second)

Answer: '33:11:45' Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 101). Wiley. Kindle Edition.

0115--Function--Essay: What value does the function --max('Hello world')-- return?

Answer: 'w' The max function tells us the "largest character" in the string (which turns out to be the letter "w") and the min() function shows us the smallest character (which turns out to be a space). (PFE pg 43) End Answer E E

0205--Indices--MultipleChoice: Based on the following code, what will the slice operation yield given the value in the bracket operator? a. >>> fruit = 'banana' b. >>> fruit[3:3] c. ___a._______ f. Choices are below**************************** 1. (a.) '' 2. (a.) ban 3. (a.) ana 4. (a.) nan 5. non of the above

Answer: (1.) (a.) '' If the first index is greater than or equal to the second the result is an empty string, represented by two quotation marks. An empty string contains no characters and has length 0, but other than that, it is the same as any other string. (PFE pg 69) End Answer E E

0222--Methods--MultipleChoice: A method call is referred to as ____________. 1. an invocation 2. an instance 3. a process 4. a prosecution

Answer: (1.) an invocation A method call is called an invocation; in this case, we would say that we are invoking upper on the word. (PFE pg 72) End Answer E E

0219--Functions--MultipleChoice: What does the following code return? a. >>> help(str.capitalize) b. Choices are below**************************** 1. some simple documentation on the string method "capitalize". 2 HELP 3. full documentation on the string method "capitalize". 4. False

Answer: (1.) some simple documentation on the string method "capitalize". - >>> help(str.capitalize) Help on method_descriptor: capitalize(...) S.capitalize() -> str Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case. - a better source of documentation for string methods would be https://docs.python.org/library/stdtypes.html#string-methods. (PFE pg 72) End Answer E E

0221--Functions--MultipleChoice: The empty parentheses, in the following code, indicate that this method _________. a. new_word = word.upper() b. Choices are below**************************** 1. takes an argument 2. work only with strings 3. takes no argument. 4. is special

Answer: (1.) takes no argument (PFE pg 72) End Answer E E

0287--List--Checkbox: Based on the following code which statements are true? a. >>> t = ['a', 'b', 'c', 'd', 'e', 'f'] z. Choices are below**************************** 1. this expression t[1:3] will return ['b','c'] 2.this expression t[:4] will return ['a', 'b', 'c', 'd'] 3.this expression t[3:] will return [d,e,f] 4.this expression t[:] will return [] 5. this expression t[1:3] = ['x', 'y'] will return t = ['a', 'x', 'y', 'd', 'e', 'f']

Answer: (1.) true;(2.) true; (3.) true;(4.) false, (5.)true 8.5 List slices (PFE pg 94) End Answer E E

0137--Function--MultipleChoice: The start of a function definition is indicated by what keyword? 1. del 2. lambda 3. def 4. pass

Answer: (1.)def (PFE pg 47) End Answer E E

0136--Function--MultipleChoice: What does a function definition specify _____? 1. name of the function 2. the sequence of statement execution 3. how to access the function 4. path

Answer: (1.)name of the function; (2.)the sequence of statement execution (PFE pg 47) End Answer E E

0124--Function--MultipleChoice: What value does the function str() return for the argument 3.14159 ? 1. '3' 2. '3.14159' 3. 3.0 4. -3 5. 0

Answer: (2.) '3.14159' the function str() converts its argument to a string End Answer E E

0346--Lambda--What is the output of the following code? The topic of lambda is not explored in the DePaul text book. The topic of the map() is not explored in the DePaul textbook. So, skip this question. a. numbers = [1, 3, 6] b. newNumbers = tuple(map(lambda x: x , numbers)) c. print(newNumbers) z. Choices are below********************** 1. [1, 3, 6] 2. (1, 3, 6) 3. [2, 6, 12] 4. (2, 6, 12)

Answer: (2.) (1, 3, 6) - you need to study the uses of lambda ->>> map.__doc__ 'map(func, *iterables) --> map object\n\nMake an iterator that computes the function using arguments from\neach of th e iterables. Stops when the shortest iterable is exhausted.' https://www.programiz.com/node/675/quiz-results/175543/view

0204--Indices--MultipleChoice: Based on the following code, what will the slice operation yield given the value in the bracket operator? a. >>> fruit = 'banana' b. >>> fruit[:3] c. ___a._______ d. >>> fruit[3:] e. __b.________ f. Choices are below**************************** 1. (a.) ana 2. (a.) ban 3. (b.) ana 4. (b.) nan 5. none of the above

Answer: (2.) a. ban; (3.) b. ana If you omit the first index (before the colon), the slice starts at the beginning of the string. If you omit the second index, the slice goes to the end of the string. (PFE pg 69) End Answer E E

0220--Methods--MultipleChoice: Which statement represent the appropriate way to call a method? a. word = "short" b. Choices are below**************************** 1. upper(word) 2. new_word = word.upper() 3. word(upper) 4. word = upper()

Answer: (2.) new_word = word.upper() We call a method by appending the method name to the variable name using the period as a delimiter. For example, the method upper takes a string and returns a new string with all uppercase letters: Instead of the function syntax upper(word), it uses the method syntax word.upper(). This form of dot notation specifies the name of the method, upper, and the name of the string to apply the method to, word. (PFE pg 72) End Answer E E

0120--Function--MultipleChoice: What value does the function int() return for the argument 3.999999? 1. '4' 2. 4 3. 3 4. 0

Answer: (3.) int() can convert floating-point values to integers, but it doesn't round off; it chops off the fraction part (PFE pg 44) End Answer E E

0343--What is the output of the following program? a. result = lambda x: x * x b. print(result(5)) z. Choices are below********************** 1. lambda x: x*x 2. 10 3. 25 4. 5*5

Answer: (3.) 25 - you need to study the uses of lambda https://www.programiz.com/node/675/quiz-results/175543/view

0122--Function--MultipleChoice: What value does the function float() return for the argument 32? 1. '32' 2. -32 3. 32.0 4. -32 5. 0

Answer: (3.) 32.0 the function float() converts integers and strings to floating-point numbers (PFE pg 44) End Answer E E

0349--What is the output of the following code? a.>>>while 4 == 4: b...........print('4') z. Choices are below********************** 1. 4 is printed once 2. 4 is printed four times 3. 4 is printed infinitely until program closes 4. Syntax error

Answer: (3.) 4 is printed infinitely until program closes https://www.programiz.com/node/664/quiz-results/175787/view

0139--Function--MultipleChoice: If you print the function object without its parentheses, as show below, what information will the print function return? a. >>> def print_lyrics(): b. >>> print("I'm a lumberjack, and I'm okay.") c. >>> print('I sleep all night and I work all day.') d. >>> print(print_lyrics) e. Choice are below**************************** 1. the source code 2. the machine code 3. <function print_lyrics at 0xb7e99e9c> 4. traceback

Answer: (3.) <function print_lyrics at 0xb7e99e9c> (PFE pg 48) End Answer E E

0188--Loop--MultipleChoice: What is the value of iteration variable(itervar) and the count variable when the loop below terminates? a. count = 0 b. for itervar in [3, 41, 12, 9, 74, 15]: c. .....count = count + 1 d. print('Count: ', count) e. Choices are below**************************** 1.itervar = 0, count = 0 2.itervar = 6, count = 153 3.itervar = 15, count = 6 4.itervar = 3, count = 153

Answer: (3.) itervar = 15, count = 6 We set the variable count to zero before the loop starts, then we write a for loop to run through the list of numbers. Our iteration variable is named itervar and while we do not use itervar in the loop, it does control the loop and cause the loop body to be executed once for each of the values in the list. In the body of the loop, we add 1 to the current value of count for each of the values in the list. While the loop is executing, the value of count is the number of values we have seen "so far". Once the loop completes, the value of count is the total number of items. The total number "falls in our lap" at the end of the loop. We construct the loop so that we have what we want when the loop finishes. (PFE pg 62) End Answer E E

0217--Functions--MultipleChoice: What does the following code return? a. >>> stuff = 'Hello world' b. >>> dir(stuff) c. Choices are below**************************** 1. objects available for a method 2. classes available for a method 3. methods available for an object

Answer: (3.) methods available for an object - Python has a function called dir which lists the methods available for an object . >>> dir(stuff) ['capitalize', 'casefold', 'center', 'count', 'encode', 'endswith' , 'expandtabs', 'find', 'format', 'format_map', 'index' , 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier' , 'islower', 'isnumeric', 'isprintable', 'isspace' , 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip' , 'maketrans', 'partition', 'replace', 'rfind', 'rindex' , 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split' , 'splitlines', 'startswith', 'strip', 'swapcase', 'title' , 'translate', 'upper', 'zfill'] (PFE pg 71) End Answer E E

0065--Regex--MultipleChoice: If we want to prompt an interactive user with the sentence "what is your name?"; and we want the name to print on the line following the prompt, how would we modify the following statement? >>>name = input() 1.>>> name = input('What is your name?;') 2.>>> name = input('What is your name?\') 3.>>> name = input('What is your name?') 4.>>> name = input('What is your name?\n')

Answer: (4.) The input function -- input()-- would need a parameter of "what is your name?\n". Where the notation "\n" represents the regular expression for newline. The modification would look as follows: >>> name = input('What is your name?\n') End Answer E E

0231--Format--Operators--MultipleChoice-- With regard to format operations, which of the statements below will return the following string?: a. 'In 3 years I have spotted 0.1 camels.' b. Choices are below**************************** 1. 'In %d years I have spotted %g %s.' % (0.1, 3, 'camels') 2. 'In %d years I have spotted %g %s.' % ('camels', 0.1, 3) 3. 'In %d years I have spotted %g %s.' % [3, 0.1, 'camels'] 4. 'In %d years I have spotted %g %s.' % (3, 0.1, 'camels') 5. %'In %d years I have spotted %g %s.' (3, 0.1, 'camels') 6. all the above

Answer: (4.) 'In %d years I have spotted %g %s.' % (3, 0.1, 'camels') - 1. 'In %d years I have spotted %g %s.' % (0.1, 3, 'camels') - each format sequence should be matched to the tuple based on type and sequence within the tuple. The format sequence %d(integer) does not match the floating point number (0.1) in the first position of the tuple. Furthermore, the format sequence %g(float) does not match the integer (3) in the second position of the tuple. 2. 'In %d years I have spotted %g %s.' % ('camels', 0.1, 3) - each format sequence should be matched to the tuple based on type and sequence within the tuple. The format sequence %d(integer) does not match the string ('camels') in the first position of the tuple. Furthermore, the format sequence %s(float) does not match the integer (3) in the third position of the tuple. 3. 'In %d years I have spotted %g %s.' % [3, 0.1, 'camels'] - a tuple is create using parenthesis. In this case square brackets have been used. Consequently, the expression is not a tuple. 5. %'In %d years I have spotted %g %s.' (3, 0.1, 'camels') - The format operator is, in fact, an operator. Operators are position between operands. In this case the operands or the string 'In %d years I have spotted %g %s.' and the tuple (0.1, 3, 'camels') (PFE pg 74) End Answer E E

0274--Testing--Checkbox: What statements are true concerning the code below? a. >>> s = '1 2\t 3\n 4' b. >>> print(s) c. 1 2.....3 d. 4 e. >>> print(repr(s)) f. '1 2\t 3\n 4' z. Choices are below**************************** 1. a string with format characters , \t=tab, and \n=newline, is assigned to the variable "s" 2. the print() executes on the variable "s" and returns line (c.) and line (d.) where the format characters are invisible 3. line (e.) uses the repr() to return the sting in variable "s" with format characters. 4. all the above

Answer: (4.) all the above 7.9 Debugging (PFE pg 88) End Answer E E

0045--Operators--Multiple Choice: What are the Python identity operators? 1. as is 2. @@ 3.== 4. is 5. is not

Answer: (4.) and (5.) are identity operators Identity operators 4. is--Evaluates to true if the variables on either side of the operator point to the same object and false otherwise. 5. is not--Evaluates to false if the variables on either side of the operator point to the same object and true otherwise. - is operator tests, if two variables point the same object, not if two variables have the same value. --https://stackoverflow.com/questions/13650293/understanding-pythons-is-operator Comparison operator False 3. == --Evaluates to true if the actual values (variables or literal) on either side of the operator or equal to one another(equivalent). End Answer E E

0046--Operators--Multiple Choice: What are the Python membership operators? 1. as is 2. @@ 3.== 4. in 5. not in

Answer: (4.) and (5.) are identity operators The membership operators in Python are used to test whether a value is found within a sequence. For example, you can use the membership operators to test for the presence of a substring in a string. Two membership operators exist in Python: in - evaluates to True if the value in the left operand appears in the sequence found in the right operand. For example, 'Hello' in 'Hello world' returns True because the substring Hello is present in the string Hello world!. not in - evaluates to True if the value in the left operand doesn't appear in the sequence found in the right operand. For example, 'house' in 'Hello world' returns True because the substring house is not present in the string Hello world!.(https://geek-university.com/python/membership-operators/ in--Evaluates to true if it finds a item in the specified sequence and false otherwise. not in -- Evaluates to true if it does not finds a item in the specified sequence and false otherwise. End Answer E E

0265--FlowofExecution--MultipleChoice--What statement(s) best describe line (d.) of the following code?: a.>>>fhand = open('mbox.txt') b.>>>count = 0 c.>>>for line in fhand: d.>>> .....sline = line[0:-1] e.>>> .....if count <= 10: f.>>> ...........print(sline) g.>>> ..........count = count + 1 h.>>> else: i.>>> .....break z. Choices are below**************************** 1. creates a list from the content of the variable line 2. creates a tuple from the content of the variable line 3. extracts the first two characters of the content of variable line 4.creates a string that includes all character except the last character.

Answer: (4.) creates a string that includes all character except the last character. If we have a long string and we want to pinpoint an item towards the end, we can also count backwards from the end of the string, starting at the index number -1. By using negative index numbers, we can print out the character r, by referring to its position at the -3 index, like so: print(ss[-3]) - (https://www.digitalocean.com/community/tutorials/how-to-index-and-slice-strings-in-python-3) (PFE pg 84) End Answer E E

0281--List--Checkbox: Which statements below are true? 1. a list is a sequence of values 2. the values in a list can be any type 3. the values in a list are referred to a elements or items 4. a list can be created by enclosing its elements in square brackets 5. this expression, ['spam', 2.0, 5, [10, 20]], is a python legal representation of a list. 6. a list within another list is nested. 7. a list that contains no elements is called an empty list 8. empty brackets, []., will create an empty list 9. all the above are true

Answer: (9.) all the above are true - 8.1 A list is a sequence (PFE pg 90) End Answer E E

0060--Operators--MultipleChoice: What value is returned by statement (b.) and statement (e.)? a..>>> quotient = 7 // 3 b..>>> print(quotient) c.>>> ?? d.>>> remainder = 7 % 3 e.>>> print(remainder) f.>>> ?? 1. (c.) 5 2. (c.) 2 3. (f.) 1 4. (f.) 3

Answer: (c.) = 2; (f.) = 1 The floored operator(//) in divides two integers and truncate the result to an integer. The modulus operator(%) works on integers and yields the remainder when the first operand is divided by the second.(PFE pg 22-24) End Answer E E

0121--Function--MultipleChoice: What value does the function int() return for the argument -2.999999? 1. '2' 2. -2 3. 3 4. -3 5. 0

Answer: -2 int() can convert floating-point values to integers, but it doesn't round off; it chops off the fraction part (PFE pg 44) End Answer E E

0498--File--Essay: After "outfile.write('T')" executes, what will the write() function return to the terminal?

Answer: 1 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 115). Wiley. Kindle Edition.

0448--Function--Multiple: the following code returns what value to line (c.) a.table = str.maketrans('abcdef', 'uvwxyz') b.'fad'.translate(table) c. Choices below: 1. zux 2. abc 3. xyz 4. def

Answer: 1 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0152--Function--True or False: Which statement below is true concerning the reason to use a function? 1. Creating a new function gives you an opportunity to name a group of statements, which makes your program easier to read, understand, and debug. 2. Functions can make a program smaller by eliminating repetitive code. Later, if you make a change, you only have to make it in one place. 3. Dividing a long program into functions allows you to debug the parts one at a time and then assemble them into a working whole. 4. Well-designed functions are often useful for many programs. Once you write and debug one, you can reuse it. 5. User-defined function always return a string, and integer or floating point value.

Answer: 1, 2, 3, and 4 are true. Neither user-defined functions nor built-in functions need to return a value. Those that don't return a value will a data type of "None". (PFE pg 52) End Answer E E

0535--OOP GUI--True or False: This program has a few undesirable properties. These properties are not coherent with OOP. What are these properties? a. def clicked(): b. 'prints day and time info' c. time = strftime('Day: %d %b %Y\nTime: %H:%M:%S %p\n', d. localtime()) e. showinfo(message=time) f. g. root = Tk() h. button = Button(root, i. text='Click it', j. command=clicked) #button click event handler k. button.pack() l. root.mainloop() 1. The name "button" on line (h.) has global scope. 2. The name "clicked" on line (j.) has global scope. 3. The window widget root is "outside of the application,". 4. The program is not encapsulated into a single named component (function or class) that can be cleanly referred to and incorporated into a larger GUI. 5. All the above

Answer: 1, 2, 4 - (3. We ignore the window widget root as it is really "outside of the application," as we will see soon.) Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 313). Wiley. Kindle Edition.

0182--Loop--True or FALSE : Based on the following code, choose all that apply: a. n = 10 b. while True: c. .....print(n, end=' ') d. .....n = n - 1 e. print('Done!') f. Choices are below**************************** 1. the while statement will terminate when the variable "n" equal zero. 2. the statement -- print(n, end=' ') -- will fail because the variable "end" is not initialized before the execution of the print function 3. the condition in the while header will change to False when the value of the variable "n" reaches zero.

Answer: 1. False; 2. False; 3. False (PFE pg 58) End Answer E E

0225--Functions--T\F: Which of the following statements are True with regard to the "startswith" method? 1. the startswith method does not take an argument. 2. the startswith method is case sensitive. 3. the startswith method returns a boolean value.

Answer: 1. False; 2. True; 3. True Some methods such as startswith return boolean values. >>> line = 'Have a nice day' >>> line.startswith('Have') True >>> line.startswith('h') False You will note that startswith requires case to match, so sometimes we take a line and map it all to lowercase before we do any checking using the lower method. (PFE pg 73) End Answer E E

0276--Testing--Checkbox: Quality Assurance is _________. 1. is a process focused on insuring the quality of a software product. 2. the process that python uses to automatically close files 3. a process that identifies problems before a product is released. 4. all the above

Answer: 1. True; 2. False; 3. True 7.10 Glossary (PFE pg 89) End Answer E E

0275--Pythonic--Checkbox: Pythonic is ________. 1. a technique that works elegantly in Python. 2. when a technique like try and except is used to recover from missing files 3. a process describe how files are overwritten by the write mode 4. all the above

Answer: 1. True; 2. True; 3. False 7.10 Glossary (PFE pg 89) End Answer E E

0277--TryExcept--Checkbox: The term to catch is associated with the ________. 1. the try/except statement 2.prevention of an uncontrolled error stopping program execution. 3. game of baseball. 4. all the above

Answer: 1. True; 2. True; 3. False 7.10 Glossary (PFE pg 89) End Answer E E

0181--Loop--True or False: While statements: 1. typically have a condition as part of the header 2. typically have and iteration variable in the body of the While statement 3. will loop infinitely if the iteration variable is modified 4. terminate automatically if there are no statements in the body 5. will iterate until the condition in the header is False

Answer: 1. True; 2. True; 3. False; 4. False; True (PFE pg 58) End Answer E E

0254--Files--MultipleChoice--Which of the following statements concerning opening files are True?: 1.the statement fhand = open('mbox.txt') will open the file mbox.txt. 2. the open () function make a request to the operating system to find the file name and to insure that the file does exists. 3. the open() returns the actual content of a file 4. the open() returns the file handle. 5. if the file does not exist the open() will return a traceback 6. all the above

Answer: 1. True; 2. True; 3. False; 4. True; 5. True (PFE pg 80, 7.3 Text files and lines) End Answer E E

0223--Functions--MultipleChoice: Which of the following statements are True with regard to the "find" method? 1. the find method take an argument 2. the find method can take two arguments 3. the find method returns True or False 4. the find method returns the position of the target string or character. 5. the find method can start a search at the index given by the second argument. 6. the find method return the number of characters specified by the second argument.

Answer: 1. True; 2. True; 3. False; 4. True; 5. True; 6. False - (PFE pg 73) End Answer E E

0230---Format--Operators--MultipleChoice-- With regard to format operations, choose the properties that are True: a. >>> 'In %d years I have spotted %g %s.' % (3, 0.1, 'camels') b. 'In 3 years I have spotted 0.1 camels.' d. Choices are below**************************** 1. the format sequence__%d__is used to format an integer 2. the format sequence__%g__ is used to format a floating-point number (don't ask why) 3. the format sequence __%s__ is used to format a string. 4. none of the above are True

Answer: 1. True; 2. True; 3. True If there is more than one format sequence in the string, the second argument(second operand following the % operator) has to be a tuple 'In %d years I have spotted %g %s.' --> this string(first operand) has three format sequences-%d,%g and %s This tuple--second operand following the operator "%"-- has three positional items that will be to the format sequences in the order of their position(3, 0.1, 'camels') (A tuple is a sequence of comma-separated values inside a pair of parenthesis. We will cover tuples in Chapter 10). Each format sequence is matched with an element of the tuple, in order. The following example uses %d to format an integer, %g to format a floating-point number (don't ask why), and %s to format a string: >>> 'In %d years I have spotted %g %s.' % (3, 0.1, 'camels') 'In 3 years I have spotted 0.1 camels.' (PFE pg 74) End Answer E E

0256--Tuples--MultipleChoice--Which statements are true with regard to the following code: a. txt = 'but soft what light in yonder window breaks' b. words = txt.split() c. t = list() d. for word in words: e...... t.append((len(word), word)) f....t.sort(reverse=True) g. res = list() h. for length, word in t: i. res.append(word) j. print(res) z. Choices are below**************************** 1.(a.) assigns a string to the variable txt 2.(b.) creates a list by delimiting the string with commas based on the space between words in the string. The resulting list is assigned to the list variable words 3.(c.) creates the list variable t 4.(d.) creates a for header with index 'word' and the list 'words' 5.(e.) will add a tuple element to the list variable t. The tuple element will contain the length of the word (element of the list words) and the value of the element from the list words. 6. (f.)sort the elements of list variable t in decreasing order. 7. (f.)sort compares the first element, length, first, and only considers the second element to break ties. 8.(g.)creates the list variable res 9.(h) based on the tuple element pattern (length, word) the list variable t is used to populate the list variable res. Fo, the for loop traverse the list variable t in sequence and extract the tuple element pattern (length, word) based on the second element(word). 10. all the above

Answer: 1. True; 2. True; 3. True; 4. True; 5. True; 6.True; 7. True; 8. True; 9. True why does this statement return a tuple as an element of a list? - d. for word in words: e. t.append((len(word), word)) (PFE pg 119, Tuples) End Answer E E

0263--Newline--MultipleChoice--Which statement explains the double line spacing output when the following code is executed?; a. fhand = open('mbox-short.txt') b. for line in fhand: c......if line.startswith('From:'): d...........print(line) e. f.When this program runs, we get the following output: g. h. From: [email protected] i. j. From: [email protected] k. l.From: [email protected] m. n. From: [email protected] z. Choices are below**************************** 1. the record extracted from the file mbox-short.txt include the original newline character associated to the record. The print function added and additional newline character when the record is written to the terminal. 2.the print() adds two newline characters when startswith() is used. 3. the for loop adds a blank line each time it loops to the top of the file mbox-short.txt 4.the file mbox-short.txt has two newline characters per record.

Answer: 1. the record extracted from the file mbox-short.txt include the original newline character associated to the record. The print function added and additional newline character when the record is written to the terminal. - Each of the lines(in the file mbox-short.txt) ends with a newline, so the print statement prints the string in the variable line which includes a newline and then print adds another newline, resulting in the double spacing effect we see. (PFE pg 83) End Answer E E

0293--ListMethod--Checkbox: The following code will________ a.>>> t = ['a', 'b', 'c'] b.>>> x = t.remove('b') c.>>> print(x) d.>>> print(t) e.>>> t = ['a', 'b', 'c', 'b'] f.>>> x = t.remove('b') g.>>> print(x) h.>>> print(t) z. Choices are below**************************** 1. have statement(d.) return ['a', 'c'] 2. have statement(b.) updates "t" without an explicit index assignment 3. have the return values from lines (c.) and (g.) equal "None" 4. have statement(h.) return ['a', 'c']

Answer: 1. true; 2. true; 3. true; 4.false >>> >>> t = ['a', 'b', 'c'] >>> x = t.remove('b') >>> print(x) None >>> print(t) ['a', 'c'] >>> t = ['a', 'b', 'c', 'b'] >>> x = t.remove('b') >>> print(x) None >>> print(t) ['a', 'c', 'b'] >>> 8.7 Deleting elements (PFE pg 95) End Answer E E

0291--ListMethod--Checkbox: Based on following code the pop method will______. a. >>> t = ['a', 'b', 'c'] b. >>> x = t.pop(1) c. >>> print(x) d. >>> print(t) z. Choices are below**************************** 1.modify the list(on line(b.)) and return the value of the deleted element(on line(c.)). 2. (on line(b.)) delete the last value in the list if the pop method is not provide an argument, this case an index, that is related to the list. 3. the pop method is void 4. all the above

Answer: 1. true; 2. true;3. False >>> t = ['a', 'b', 'c'] >>> x = t.pop(1) >>> print(x) b >>> print(t) ['a', 'c'] >>> 8.7 Deleting elements (PFE pg 94) End Answer E E

0425--Function-- What is the result of the following code?: for name in ['Joe', 'Sam', 'Tim', 'Ann']: print(name, end='! ') 1.Joe! Sam! Tim! Ann! 2.Joe! Sam! Tim! Ann! 3 Joe!Sam!Tim!Ann! 4.Ann!

Answer: 2 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 99). Wiley. Kindle Edition.

0484--Text--If quotes delimit a string value, how do we construct strings that contain quotes? Which one of the following is True: 1. excuse = 'I am "sick"'; print(excuse) ->Traceback 2. excuse = 'I am "sick"'; print(excuse) -> I am "sick" 3. excuse = 'I am "sick"'; print(excuse) -> 'I am "sick"'

Answer: 2 - If the text contains a single quote, we can use double quote delimiters, and if contains double qoutes you can use single quote delimters . Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 92). Wiley. Kindle Edition.

0218--Functions--MultipleChoice: What does the following code return? a. >>> stuff = 'Hello world' b. >>> type(stuff) c. Choices are below**************************** 1. objects available for a method 2. object class 3. methods available for and object

Answer: 2. >>> type(stuff) <class 'str'> The type function shows the type of an object. (PFE pg 71) End Answer E E

0353--Regex--The expression "re.search('^From:', line)" in the code below is equivalent to what method? a.>>>import re b.>>>hand = open('mbox-short.txt') c.>>>for line in hand: d...............line = line.rstrip() e................if re.search('^From:', line): d......................print(line) z. Choices are below********************** 1. find() 2. startswith() 3. endswith() 4. all the above

Answer: 2. startswith() Regular expressions (PFE pg 127) End Answer E E

0193--Loop--t\f: The value of the variable "smallest" after the fourth iteration of the for loop is 3? a. smallest = None b. print('Before:', smallest) c. for itervar in [3, 41, 12, 9, 74, 15]: d. .....if smallest is None or itervar < smallest: e. ..........smallest = itervar f. .....print('Loop:', itervar, smallest) g. print('Smallest:', smallest) h. Choices are below****************************

Answer: 3 (PFE pg 63) End Answer E E

0423--Function--Match to Definition: s.find(target) 1. A copy of string s with the first character capitalized if it is a letter in the alphabet 2. The number of occurrences of substring target in string s 3. The index of the first occurrence of substring target in string s 4. A copy of string s converted to lowercase 5. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 6. A copy of string s in which characters have been replaced using the mapping described by table 7. A list of substrings of strings s, obtained using delimiter string sep; the default delimiter is the blank space 8. A copy of string s with leading and trailing blank spaces removed 9. A copy of string s converted to uppercase

Answer: 3 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0406--Methods--Match: s.lower() 1. A copy of string s with the first character capitalized if it is a letter in the alphabet 2. The number of occurrences of substring target in string s 3. The index of the first occurrence of substring target in string s 4. A copy of string s converted to lowercase 5. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 6. A copy of string s in which characters have been replaced using the mapping described by table 7. A list of substrings of strings s, obtained using delimiter string sep; the default delimiter is the blank space 8. A copy of string s with leading and trailing blank spaces removed 9. A copy of string s converted to uppercase

Answer: 4 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0352--The import statement in the code below refers to which library? a.>>>import re b.>>>hand = open('mbox-short.txt') c.>>>for line in hand: d...............line = line.rstrip() e................if re.search('From:', line): d......................print(line) z. Choices are below********************** 1. Return 2. Recover 3. Redo 4. Regular Expression

Answer: 4. Regular Expression Regular expressions (PFE pg 127) End Answer E E

0354--Regex--The search string 'ˆFrom:.+@' will successfully match lines that start with "From:", followed by one or more characters (.+), followed by an at-sign. Which lines below will match the search string? a.>>>re.search('^From: .+@', line): z. Choices are below********************** 1. From:[email protected] 2. From:[email protected], [email protected], and cwen @iupui.edu 3. From:_stephen.marquard @uct.ac.za, 4. all the above

Answer: 4. all the above 11.1 Character matching in regular expressions (PFE pg 128) End Answer E E

0271--FileWriting--MultipleChoice--What does the write method in the following code return?: a. >>> fout = open('output.txt', 'w') b. >>> line1 = "This here's the wattle,\n" c. >>> fout.write(line1) z. Choices are below**************************** 1. the next line number 2.the text of the line written the variable fout 3. True 4. the number of characters written

Answer: 4. the number of characters written;in this case 24 7.8 Writing files(PFE pg 88) End Answer E E

0229B--Format--Operators--True or False: The following code will return: 'I have spotted 42 camels.' a. >>> camels = 42 b. >>> 'I have spotted %d camels.' % camels c. Choices are below****************************

Answer: 5. True

0229--Format--Operators--True or False: Based on the code below, which of the following statements concerning format operations is True? a. >>> camels = 42 b. >>> 'I have spotted %d camels.' % camels c. 'I have spotted 42 camels.' d. Choices are below**************************** 1. the first operand of a format operation is the format string. 2. The second operand of a format operation is string that will be formatted. 3. The format string of a format operation can contain one or more format sequences. 4. A format operation returns a string. 5. all the above are True

Answer: 5. all the above are True The first operand is the format string, which contains one or more format sequences that specify how the second operand is formatted. The result is a string. (PFE pg 74) End Answer E E

0421--Function-- Match to Definition: s.capitalize() 1. The number of occurrences of substring target in string s 2 The index of the first occurrence of substring target in string s 3. A copy of string s converted to lowercase 4. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 5. A copy of string s in which characters have been replaced using the mapping described by table 6. A list of substrings of strings s, obtained using delimiter string sep; the default delimiter is the blank space 7. A copy of string s with the first character capitalized if it is a letter in the alphabet 8. A copy of string s with leading and trailing blank spaces removed 9. A copy of string s converted to uppercase 0016--functions and methods

Answer: 7 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0449--Function--Multiple:The following code will return what value? s = '2;3;5;7;11;13' s.split(';') Choices below: 1. A copy of string s with the first character capitalized if it is a letter in the alphabet 2. The number of occurrences of substring target in string s 3. The index of the first occurrence of substring target in string s 4. A copy of string s converted to lowercase 5. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 6. A copy of string s in which characters have been replaced using the mapping described by table 7. A list of items of strings s, obtained using delimiter string sep(in this case ";"); the default delimiter is the blank space 8. A copy of string s with leading and trailing blank spaces removed 9. A copy of string s converted to uppercase

Answer: 7 -A list of items of strings s, obtained using delimiter string sep(in this case ";"); the default delimiter is the blank space ->>> s = '2;3;5;7;11;13' >>> s.split(';') ['2', '3', '5', '7', '11', '13'] >>> s '2;3;5;7;11;13' >>> smode = s.split(';') >>> smode ['2', '3', '5', '7', '11', '13'] Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0269--TryExcept--MultipleChoice--Which statements below offer the best description of the following code? a. fname = input('Enter the file name: ') b. try: c. fhand = open(fname) d. except: e. print('File cannot be opened:', fname) f. exit() z. Choices are below**************************** 1. statement (a.) take input from the terminal by prompting the user with "Enter the file name: " 2. statement (b.) is the beginning of a try header 3. statement (c.) is the body of the try statement. 4. statement (d.) is except header statement 5. statements (e.) and (f.) are the body of the except statement 6. statement (e.) will terminate the program when an exception is detected 7. all the above

Answer: 7. all the above - 7.7 Using try, except, and open (PFE pg 87) End Answer E E

Match 0452-Function--Multiple: s.strip() 1. A copy of string s with the first character capitalized if it is a letter in the alphabet 2. The number of occurrences of substring target in string s 3. The index of the first occurrence of substring target in string s 4. A copy of string s converted to lowercase 5. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 6. A copy of string s in which characters have been replaced using the mapping described by table 7. A list of substrings of strings s, obtained using delimiter string sep; the default delimiter is the blank space 8. A copy of string s with leading and trailing blank spaces removed 9. A copy of string s converted to uppercase

Answer: 8 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0422--Function--Match to Definition: s.count(target) 1. The index of the first occurrence of substring target in string s 2. A copy of string s converted to lowercase 3. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 4. A copy of string s in which characters have been replaced using the mapping described by table 5. A list of substrings of strings s, obtained using delimiter string sep; the default delimiter is the blank space 6. A copy of string s with the first character capitalized if it is a letter in the alphabet 7. A copy of string s with leading and trailing blank spaces removed 8. A copy of string s converted to uppercase 9. The number of occurrences of substring target in string s

Answer: 9 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0450--Function--Multiple: s.upper() 1. A copy of string s with the first character capitalized if it is a letter in the alphabet 2. The number of occurrences of substring target in string s 3. The index of the first occurrence of substring target in string s 4. A copy of string s converted to lowercase 5. A copy of string s in which every occurrence of substring old, when string s is scanned from left to right, is replaced by substring new 6. A copy of string s in which characters have been replaced using the mapping described by table 7. A list of substrings of strings s, obtained using delimiter string sep; the default delimiter is the blank space 8. A copy of string s with leading and trailing blank spaces removed 9. A copy of string s converted to uppercase

Answer: 9 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 97). Wiley. Kindle Edition.

0140--Function--MultipleChoice: Given that "print_lyrics" is a function, what will the following code ---type(print_lyrics)---return? 1. <function print_lyrics at 0xb7e99e9c> 2. <class 'function'> 3. traceback 4. 0

Answer: <class 'function'> (PFE pg 48) End Answer E E

0131--Function--MultipleChoice: If you print the module object as show below, what information will the print function return? a. >>> import math b. >>> print(math) c. choices are below********************* 1. the source code 2. the machine code 3. <module 'math' (built-in)> 4. traceback

Answer: <module 'math' (built-in)> (PFE pg 45) End Answer E E

0468--OOP-- True or False:???: The new implementation of class Point supports the "==" operator in a way that makes sense >>> Point(3, 5) == Point(3, 5) True and also ensures that the contract between the constructor and the operator repr() is satisfied: >>> Point(3, 5) == eval(repr(Point(3, 5))) True

Answer: ??? Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 262). Wiley. Kindle Edition.

0144--Function--True or False: Using a user defined function within another user defined function will not result in a traceback. For example: def repeat_lyrics(): print_lyrics() print_lyrics()

Answer: ??True -- Once you have defined a function, you can use it inside another function. (PFE pg 48) the author does not distinguish between user-defined function and built-in functions. I would assume that built-in function can be used inside user-defined functions. However, can user-defined function operate inside built-in functions? End Answer E E

0172--Function--MultipleChoice: What will the following Python program print out? a. def fred(): b. ..... print("Zap") c. def jane(): d. ..... print("ABC") e. jane() f. fred() g. jane() h. Choices are below**************************** 1. Zap ABC jane fred jane 2. Zap ABC Zap 3. ABC Zap jane 4. ABC Zap ABC 5. Zap Zap Zap

Answer: ABC Zap ABC (PFE pg 54) End Answer E E

0047--Operators--What are the Python logical operators? 1. NOR 2. False 3. True 4. NOT 5. AND 6. OR 7. all the above

Answer: AND;OR; NOT End Answer E E

0051--Function--Essay: What value will the Python function "type (x )" return?

Answer: Data type. For the parameter "x', type() will return the data type--string(str), integer(int), floating point(float) of the value held in "x'. End Answer E E

00442--Function--Why will the execution of this code result in an error?: >>>print(f(3)) >>>def f(x): ............ return x**2 + 1

Answer: Executed before definition. When a module is executed, the Python statements are executed top to bottom. The print(f(3)) statement will fail because the name f is not defined yet. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 71). Wiley. Kindle Edition.

0029--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "F"? 1. far 2. from 3. frame 4. finally 5. for 6. false

Answer: FALSE;for;from;finally End Answer E E

0538--OOP GUI--True or False: The the execution of line (b.) in the following will return a standard GUI window. a. >>> from tkinter import Tk b. >>> root = Tk()

Answer: False If you execute the preceding code, you will notice that creating a Tk() widget did not get you a window on the screen. To get the window to appear, the Tk method mainloop() needs to be invoked on the widget: >>> root.mainloop() Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 292). Wiley. Kindle Edition.

0407--Function--True or False: The function len(['g', '1', 't', '8', '9', 'm', 'b']) return the number of characters(28) between the square brackets.

Answer: False Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 72). Wiley. Kindle Edition

0211A--Indices--True or False: myCat will equal 'cymric cat' after statement (b.) completes. a. >>> myCat = 'cymric bat' b. >>> myCat[7] = 'c' c. >>> myCat == 'cymric cat' d. Choices are below****************************

Answer: False Suppose that we misspelled the type of cat: >>> myCat = 'cymric bat' We would like to correct the mistake by changing the character at index 7 from a 'b' to a 'c'. Let's try: >>> myCat[7] = 'c' Traceback (most recent call last): File "<pyshell#35>", line 1, in <module> myCat[7] = 'c' TypeError: 'str' object does not support item assignment The error message essentially says that individual characters (items) of a string cannot be changed (assigned to). We say that strings are immutable. Does that mean that we are stuck with a misspelled value for myCat? No, not at all. We can simply reassign a brand new value to variable myCat: >>> myCat = 'cymric cat' >>> myCat 'cymric cat' Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 29). Wiley. Kindle Edition. End Answer E E

0211D--Indices--True or False: The following code will traceback: a. >>> myCat = 'cymric bat' b. >>> print(myCat) c. cymric bat d. >>> myCat = 'cymric cat' e. Choices are below****************************

Answer: False We say that strings are immutable. Does that mean that we are stuck with a misspelled value for myCat? No, not at all. We can simply reassign a brand new value to variable myCat: >>> myCat = 'cymric cat' >>> myCat 'cymric cat' Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 29). Wiley. Kindle Edition. End Answer

0225D--Functions--T\F: In the following code, "line" is invoked on to "startswith". a. >>> line = 'Have a nice day' b. >>> line.startswith('Have') c. Choices are below****************************

Answer: False - this nomenclature is unclear--review

0533--GAE--CSC 401 Introduction to Programming Note: There are three versions of the Graduate Assessment Exam for CSC 401: a Python version, a Java version, and a C++ version. Students should take the exam based on the programming language they are most familiar with. Students who plan to pursue the MS Computational Finance program must take the Python version of the exam. Topics Variables, assignments, and expressions involving arithmetic, unary, relational, and conditional operators; Core built-in data types Python: int, bool, float, str, list, two-dimensional lists; Java: int, double, boolean, and char primitive types, java.lang.String class, arrays, two-dimensional arrays C++: int, double, bool, and char types, standard string class, arrays, two-dimensional arrays Control flow structures (if, for, while, break, continue statements) Functions (static methods in Java), parameter passing, return statement, function scope Interactive and file Input/Output Python: print, open, input Java: System.in, System.out, java.io.File, java.io.IOException, java.util.Scanner C++: iostream, fstream Recursion References: Java: Java: An Introduction to Problem Solving and Programming, 6/E Walter Savitch, Addison-Wesley, 2012 C++: Problem Solving with C++, 8/E Walter Savitch, Addison-Wesley, 2012 Python: Introduction to Computing Using Python Ljubomir Perkovic, Wiley, 2011.

Answer: GAE 1.Variables 2. Assignment 3. arithmetic expressions 4. unary expressions 5. relational expressions(>=, <=,<,>,!=,==, is, is not, in, not in) 6. conditional operator expressions(if,if..else, elif) 7. built-in data types int 8. built-in data types bool 9. built-in data types float 10. built-in data types list 11. two-dimensional list(dictionary) 12. Control Flow: if, while, break, contiinue 13. Function parameter passing 14. Function return statement 15. Function scope 16. Interactive (terminal input) 17. File input/output 18. print(), open() and input() 19. Recursion

0187--Loop--MultipleChoice: During the first iteration of the for loop below the value of the variable "friend" is _______? a. friends = ['Joseph', 'Glenn', 'Sally'] b. for friend in friends: c. ..... print('Happy New Year:', friend) d. print('Done!') e. Choices are below**************************** 1. Joseph 2. Glen 3. Sally 4. None

Answer: Joseph In particular, friend is the iteration variable for the for loop. The variable friend changes for each iteration of the loop and controls when the for loop completes. The iteration variable steps successively through the three strings stored in the friends variable. (PFE pg 61) End Answer E E

0420--Function--Yes or No: Will the replace method message.replace('top', 'no') modify the string message?

Answer: No - The string message was not changed by the replace() method. Instead, a copy of message, with appropriate substring replacements, got returned. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 96). Wiley. Kindle Edition.

0146--Function--Yes or No: The definition of print_lyrics() follows the definition of repeat_lyrics(). Will the definition of repeat_ lyrics) fail because print_lyrics() has not been defined? a. def repeat_lyrics(): b. ..... print_lyrics() c. ..... print_lyrics() d. def print_lyrics(): e. ..... print("I'm a lumberjack, and I'm okay.") f. ..... print('I sleep all night and I work all day.') g. repeat_lyrics()

Answer: No. -- The statements inside the function do not get executed until the function is called. However, Function definitions get executed just like other statements, but the effect is to create function objects. (this creating a function object seems akin to setting aside memory for when the function is actually executed.) (PFE pg 49) End Answer E E

0151--Function--MultipleChoice: What will the following code return?: a. def addtwo(a, b): b. .....added = a + b c. x = addtwo(3, 5) d. print(x) c. Choices are below**************************** 1. 8 2. 5 3. 2 4. None #

Answer: None The return statement is used to return a value from the function. The return statement is not mandatory, some function return values while other don't. If a function doesn't have return statement in the body then a reserved keyword None is returned automatically. None is actually an object of a built-in type NoneType. Don't worry if you find return statement confusing; they are not, we will discuss return statement in detail in the upcoming section. -- https://overiq.com/python/3.4/functions-in-python/ End Answer E E

0226--Functions--MultipleChoice: Which of the following statements are True with regard to the following code? a.>>> line = 'Have a nice day' b.>>> line.lower() c.>>> line.lower().startswith('h') d. Choices are below**************************** 1. Statement a. will return False 2. Statement b. needs an argument 3. Statement b. will return "Have a nice day" 4. Statement c. will return a traceback. 5. None are True

Answer: None are true - a.>>> line = 'Have a nice day' b.>>> line.startswith('h') c. False d.>>> line.lower() e. 'have a nice day' f. >>> line.lower().startswith('h') g. True The method "startswith" is called with a argument of "h". The method "startswith" returns a value of False as the lowercase "h" does not start the string value contained in the variable "line". The call of the method(d.) "lower" returns a value of (e.) 'have a nice day'. Next, the method startswith(f.) ,with an argument of "h" ,is appended to the invocation "line.lower() using dot notation. The invocation of the method lower on to the the variable "line" returns the string 'have a nice day'. The startswith method on on line (f.) interprets the value returned by the method lower and determines that "h" does exist in the first position of the string returned by the "lower" method. As long as we are careful with the order, we can make multiple method calls in a single expression. (PFE pg 73) End Answer E E

0441--Function--True or False: The range() function creates a sequence on numbers in a given range. For range(5), the function creates the sequence 0,1,2,3,4

Answer: The built-in function range() can be used together with the for loop to iterate over a sequence of numbers in a given range. Here is how we can iterate over the integers 0, 1, 2, 3, 4: >>> for i in range(5): print(i) 0 1 2 3 4 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 66). Wiley. Kindle Edition.

0207--Indices--MultipleChoice: What is the result of the assignment operation in the code below?; a. >>> greeting = 'Hello, world!' b. >>> greeting[0] = 'J' f. Choices are below**************************** 1. greeting == Jello, world! 2. greeting == ello, world! 3. greeting == None 4. Traceback

Answer: Traceback TypeError: 'str' object does not support item assignment The "object" in this case is the string and the "item" is the character you tried to assign. For now, an object is the same thing as a value, but we will refine that definition later. An item is one of the values in a sequence. The reason for the error is that strings are immutable, which means you can't change an existing string. (PFE pg 70) End Answer E E

0119--Function--MultipleChoice: What does the function int() return when its argument is the string "Hello"? 1. 5 2. 3 3. trackback 4. 0

Answer: Traceback ValueError: invalid literal for int() with base 10: 'Hello' (PFE pg 44) End Answer E E

0408--Function--True or False: The function len(...) return the number of items of a sequence or mapping.

Answer: True

0186--Loop--True or False: the for statement is a definite loop because it loops through a known set of items. A for loop executes through as many iterations as there are items in the set.

Answer: True (PFE pg 60) End Answer E E

0191--True or False: The built-in functions sum() will compute the sum total numeric value of the items in a list.

Answer: True (PFE pg 62) End Answer E E

0196--Slice--True are False: The bracket operator in the code below allows the program to access the elements of a character string one at a time. a.>>> fruit = 'banana' b. >>> letter = fruit[1] c. Choices are below****************************

Answer: True (PFE pg 67) End Answer E E

0321--Tuple--True are False: Based on the following code, x equals 'have' and y equals 'fun': a. >>> m = [ 'have', 'fun' ] b. >>> (x, y) = m z. Choices are below**********************

Answer: True - Stylistically when we use a tuple on the left side of the assignment statement, we omit the parentheses, but >>> (x, y) = m is valid syntax: 10.3 Tuple assignment (PFE pg 120) End Answer E E

0108--Boolean--T/F--Boolean expressions are created with logical operators.

Answer: True (PFE pg 40, this definition has been adapted for t/f) End Answer E E

0141--Function--True or False: Defining a function creates a variable with the same name.

Answer: True (PFE pg 47) End Answer E E

0149--Function--True or False: The function's argument is evaluated before the function is called.

Answer: True (PFE pg 50) ??arguments are only evaluated once.?? End Answer E E

0153--Definition--t\f: An algorithm is a general process for solving a category of problems.

Answer: True (PFE pg 53) End Answer E E

0190--True or False: The built-in functions len() will compute the number of items in a list.

Answer: True (PFE pg 62) End Answer E E

0192--Loop--t\f: The value of the variable "largest" after the fourth iteration of the for loop is 41? a. largest = None b. print('Before:', largest) c. for itervar in [3, 41, 12, 9, 74, 15]: d. ....if largest is None or itervar > largest : e. .......... largest = itervar f. ....print('Loop:', itervar, largest) g. print('Largest:', largest) h. Choices are below****************************

Answer: True (PFE pg 63) End Answer E E

0201--Definition--True or False: Traversal means to process the whole sequence one element at a time-- starting at the extreme.

Answer: True (PFE pg 68) End Answer E E

0258--Files--True or False: The Python newline character(\n) is interpreted as a single character. For example: a. >>> stuff = 'X\nY' b. >>> print(stuff) c. X d. Y e. >>> len(stuff) f. 3 z. Choices are below****************************

Answer: True 7.3 Text files and lines(PFE pg 81) End Answer E E

0409--Function--True or False: The function len(), for example, takes a sequence (a string or a list, say) and returns the number of items in the sequence.

Answer: True >>> len('goldfish') 8 >>> len(['goldfish', 'cat', 'dog']) 3 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 67). Wiley. Kindle Edition.

0234--Functions--True or False: The len() function/method is able to compare an empty string to an integer

Answer: True >>> line = '' >>> if len(line) == 0: ... print('the len() is able to compare empty strings to intergers') ... else: ... print('False') ... the len() is able to compare empty strings to intergers >>> End Answer E E

0160--Function--t\f: Fruitful functions are those that return a value.

Answer: True A function that returns a value. (PFE pg 53) End Answer E E

0178--Definition--t\f: Infinite loops have termination conditions that are never satisfied.

Answer: True A loop in which the terminating condition is never satisfied or for which there is no terminating condition. (PFE pg 64) End Answer E E

0168--Function--t\f: A parameter is a name used inside a function to refer to the value passed as an argument.

Answer: True A name used inside a function to refer to the value passed as an argument. (PFE pg 53) End Answer E E

0163--Function--t\f: Function definition is a statement that creates a new function, specifying its name, parameters, and the statements it executes.

Answer: True A statement that creates a new function, specifying its name, parameters, and the statements it executes. (PFE pg 53) End Answer E E

0162--Function--t\f: A function call is a statement that executes a function. It consists of the function name followed by an argument list.

Answer: True A statement that executes a function. It consists of the function name followed by an argument list. (PFE pg 53) End Answer E E

0166--Function--t\f:An import statement reads a module file and creates a module object.

Answer: True A statement that reads a module file and creates a module object. (PFE pg 53) End Answer E E

0164--Function--t\f:A function object is a value created by a function definition. The name of the function is a variable that refers to a function object.

Answer: True A value created by a function definition. The name of the function is a variable that refers to a function object. (PFE pg 53) End Answer E E

0167--Function--t\f:: A module object is a value created by an import statement that provides access to the values defined in a module.

Answer: True A value created by an import statement that provides access to the values defined in a module. (PFE pg 53) End Answer E E

0154--Function--t\f: An argument is a value provided to a function when the function is called. This value is assigned to the corresponding parameter in the function.

Answer: True A value provided to a function when the function is called. This value is assigned to the corresponding parameter in the function. (PFE pg 53) End Answer E E

0173--Pattern--t\f:An accumulator is variable used in a loop to add up or accumulate a result.

Answer: True A variable used in a loop to add up or accumulate a result. (PFE pg 64) End Answer E E

0174--Pattern--t\f: A counter is variable used in a loop to count the number of times something happened.

Answer: True A variable used in a loop to count the number of times something happened. We initialize a counter to zero and then increment the counter each time we want to "count" something. (PFE pg 64) End Answer E E

0176--Variable--t\f: An assignment that give the initial value to a variable is said to initialize the variable.

Answer: True An assignment that gives an initial value to a variable that will be updated. (PFE pg 64) End Answer E E

0175--Pattern--t\f: A decrement is an update that decreases the value of a variable.

Answer: True An update that decreases the value of a variable. (PFE pg 64) End Answer E E

0177--Pattern--t\f: An increment is an update that increases the value of a variable.

Answer: True An update that increases the value of a variable (often by one). (PFE pg 64) End Answer E E

0426--Function--True or False: The format() string method is invoked on a string that represents the format of the output. The arguments of the format() function are the objects to be printed. For example: >>> '{0}:{1}:{2}'.format(hour, minute, second) '11:45:33'

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 100). Wiley. Kindle Edition.

0534--Unary--True or False: The not operator is a unary Boolean operator, which means that it is applied to a single Boolean expression (as opposed to the binary Boolean operators and and or). It evaluates to False if the expression is true or to True if the expression is false. >>> not (3 < 4) False Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 20). Wiley. Kindle Edition.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 20). Wiley. Kindle Edition. ition (Page 20). Wiley. Kindle Edition.

0211B--Indices--True or False: Individual characters (items) of a string cannot be assigned to an indexed element of an immutable object using a slice operation.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 29). Wiley. Kindle Edition. End Answer

0546--OOP GUI--True or False: The constructor argument "image" on line (20.) must refer to an image in a format that "tkinter" can display. The "PhotoImage class" on lines (1.) and (16.), defined in the module "tkinter", is used to transform a GIF image into an object with such a format. 1) from tkinter import Tk,Label,PhotoImage,BOTTOM,LEFT,RIGHT,RIDGE 2) #GUI illustrates widget constructor options and method pack() 3) root = Tk() 4) 5) #label with text "Peace begins with a smile." 6) text = Label(root, 7) font = ('Helvetica', 16, 'bold italic'), 8) foreground='white', #letter color 9) background='black', #background color 10) padx=25, #widen label 25 pixels left and right 11) pady=10, #widen label 10 pixels up and down 12) text='Peace begins with a smile.') 13) text.pack(side=BOTTOM) #push label down 14) 15) #label with peace symbol image 16) peace = PhotoImage(file='peace.gif') 17) peaceLabel = Label(root, 18) borderwidth=3, #label border width 19) relief=RIDGE, #label border style 20) image=peace) 21) peaceLabel.pack(side=LEFT) #push label left 22) #label with smiley face image 23) smiley = PhotoImage(file='smiley.gif') 24) smileyLabel = Label(root, 25) image=smiley) 26) smileyLabel.pack(side=RIGHT) #push label right 27) 28) root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 294). Wiley. Kindle Edition.

0547--OOP GUI--True or False:The optional argument "side"(on lines 13,21 and 26) of method "pack()" is used to direct the tkinter geometry manager to push a widget against a particular border of its master. The value of side can be TOP, BOTTOM, LEFT, or RIGHT; the default value for side is TOP. 1) from tkinter import Tk,Label,PhotoImage,BOTTOM,LEFT,RIGHT,RIDGE 2) #GUI illustrates widget constructor options and method pack() 3) root = Tk() 4) 5) #label with text "Peace begins with a smile." 6) text = Label(root, 7) font = ('Helvetica', 16, 'bold italic'), 8) foreground='white', #letter color 9) background='black', #background color 10) padx=25, #widen label 25 pixels left and right 11) pady=10, #widen label 10 pixels up and down 12) text='Peace begins with a smile.') 13) text.pack(side=BOTTOM) #push label down 14) 15) #label with peace symbol image 16) peace = PhotoImage(file='peace.gif') 17) peaceLabel = Label(root, 18) borderwidth=3, #label border width 19) relief=RIDGE, #label border style 20) image=peace) 21) peaceLabel.pack(side=LEFT) #push label left 22) #label with smiley face image 23) smiley = PhotoImage(file='smiley.gif') 24) smileyLabel = Label(root, 25) image=smiley) 26) smileyLabel.pack(side=RIGHT) #push label right 27) 28) root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 295). Wiley. Kindle Edition.

0550--OOP--True or False: The methods pack() and grid()-on lin (16.)- use different methods to compute the layout of the widgets. The short story is this: You must use one or the other for all widgets with the same master. 1 from tkinter import Tk, Label, RAISED 2 root = Tk() 3 labels = [['1', '2', '3'], #phone dial label texts 4 ['4', '5', '6'], #organized in a grid 5 ['7', '8', '9'], 6 ['*', '0', '#']] 7 8 for r in range(4): #for every row r = 0, 1, 2, 3 9 for c in range(3): #for every row c = 0, 1, 2 10 #create label for row r and column c 11 label = Label(root, 12 relief=RAISED, #raised border 13 padx=10, #make label wide 14 text=labels[r][c]) #label text 15 #place label in row r and column c 16 label.grid(row=r, column=c) 17 18 root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 298). Wiley. Kindle Edition.

0551--OOP GUI--True or False: The expression "command=compute" on line (26)executes the user-defined function compute() on line (4.) using the "command=" option. 1)from tkinter import Tk, Button, Entry, Label, END 2)from time import strptime, strftime 3)from tkinter.messagebox import showinfo 4)def compute(): 5) '''display day of the week corresponding to date in dateEnt; 6) date must have format MMM DD, YYYY (e.g., Jan 21, 1967)''' 7) global dateEnt # dateEnt is a global variable 8) # read date from entry dateEnt 9) date = dateEnt.get() 10) # compute weekday corresponding to date 11) weekday = strftime('%A', strptime(date, '%b %d, %Y')) 12) # display the weekday in a pop-up window 13) showinfo(message = '{} was a {}'.format(date, weekday)) 14) #delete date from entry dateEnt 15) dateEnt.delete(0, END) 16.root = Tk() 17)# label 18)label = Label(root, text='Enter date') 19)label.grid(row=0, column=0) 20) 21)# entry 22)dateEnt = Entry(root) #instantiate input widget 23)dateEnt.grid(row=0, column=1)#estabishes position of input widget in the window 24) 25)# button 26)button = Button(root, text='Enter', command=compute) #place input text,row1, column0; executes compute() 27)button.grid(row=1, column=0, columnspan=2) 28) 29)root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 303). Wiley. Kindle Edition.

0552--OOP GUI--True or False:Function strptime()-on line (11.)- takes as input a string containing a date (date) and a format string ('%b %d, %Y'), which uses directives from Table 4.3. The function returns the date in an object of type time.struct_time. Recall from Section 4.2 that function strftime() takes such an object and a format string ('%A') and returns the date formatted according to the format string. Since the format string contains only the directive %A that specifies the date weekday, only the weekday is returned. 1)from tkinter import Tk, Button, Entry, Label, END 2)from time import strptime, strftime 3)from tkinter.messagebox import showinfo 4)def compute(): 5) '''display day of the week corresponding to date in dateEnt; 6) date must have format MMM DD, YYYY (e.g., Jan 21, 1967)''' 7) global dateEnt # dateEnt is a global variable 8) # read date from entry dateEnt 9) date = dateEnt.get() 10) # compute weekday corresponding to date 11) weekday = strftime('%A', strptime(date, '%b %d, %Y')) 12) # display the weekday in a pop-up window 13) showinfo(message = '{} was a {}'.format(date, weekday)) 14) #delete date from entry dateEnt 15) dateEnt.delete(0, END) 16.root = Tk() 17)# label 18)label = Label(root, text='Enter date') 19)label.grid(row=0, column=0) 20) 21)# entry 22)dateEnt = Entry(root) #instantiate input widget 23)dateEnt.grid(row=0, column=1)#estabishes position of input widget in the window 24) 25)# button 26)button = Button(root, text='Enter', command=compute) #place input text,row1, column0; executes compute() 27)button.grid(row=1, column=0, columnspan=2) 28) 29)root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 304). Wiley. Kindle Edition.

0411--Function--True or False: Python does not allow calling a function before it is defined, just as a variable cannot be used in an expression before it is assigned.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 71). Wiley. Kindle Edition.

0413--Function--True or False: When a mutable object, like list object [3,6,9,12], is programmed to pass as an argument in a function call, it may be modified by the function.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 81). Wiley. Kindle Edition.

0486--Text--True or False: String values defined with the single- or double-quote delimiters must be defined in a single line. If the string is to represent multiline text, we have two choices. One is to use triple quotes,or, the second, is to encode the the text explicitly new line characters.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 93). Wiley. Kindle Edition

0157--Definition--t\f: Deterministic pertains to a program that does the same thing each time it runs, given the same inputs.

Answer: True Pertaining to a program that does the same thing each time it runs, given the same inputs. (PFE pg 53) End Answer E E

0169--Definition--t\f--Pseudorandom pertains to a sequence of numbers that appear to be random, but are generated by a deterministic program.

Answer: True Pertaining to a sequence of numbers that appear to be random, but are generated by a deterministic program. (PFE pg 53) End Answer E E

0179--Definition--t\f: Iteration is repeated execution.

Answer: True Repeated execution of a set of statements using either a function that calls itself or a loop. (PFE pg 64) End Answer E E

0255--Tuples--True or False: A Python comparison operation, involving two data sequence operands, will traverse the data sequences and compare the first elements of each operand. Then, it will compare the second element of each operand, and so on and so forth. This will continue until a match is found or until no match is found. If a match is found the comparison operation will terminate without searching for additional matches.

Answer: True The comparison operators work with tuples and other sequences. Python starts by comparing the first element from each sequence. If they are equal, it goes on to the next element, and so on, until it finds elements that differ. Subsequent elements are not considered. For example: >>> (0, 1, 2) < (0, 3, 4) True --terminate on the second element >>> (0, 1, 2000000) < (0, 3, 4) True -- terminates on the second element (PFE pg 118, Tuples) End Answer E E

0268--Functions--True or False: The exit function terminates the program.

Answer: True The exit function terminates the program. It is a function that we call that never returns. (PFE pg 87) End Answer E E

0165--Function--t\f:A header is the first line of a function definition.

Answer: True The first line of a function definition. (PFE pg 53) End Answer E E

0155--Function--t\f: The body is he sequence of statements inside a function definition.

Answer: True The sequence of statements inside a function definition. (PFE pg 53) End Answer E E

0211C--Indices--True or False: The following code will traceback: a. >>> myCat = 'cymric bat' b. >>> myCat[7] = 'c' c. Choices are below****************************

Answer: True Traceback (most recent call last): File "<pyshell#35>", line 1, in <module> myCat[7] = 'c' TypeError: 'str' object does not support item assignment Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 29). Wiley. Kindle Edition. End Answer

0156--Function--t\f:A composition uses expression as part of a larger expression, or a statement as part of a larger statement.

Answer: True Using an expression as part of a larger expression, or a statement as part of a larger statement. (PFE pg 53) End Answer E E

0410--Function--True or False: The execution of a function ends when the return statement is executed or when the last statement in the function body is executed.

Answer: True def squareSum(x, y): return x**2 + y**2 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 68). Wiley. Kindle Edition.

0261--Files--True or False: It is a good idea to store the output of read() as a variable because each call to read() exhausts the resource: a.>>> fhand = open('mbox-short.txt') b.>>> print(len(fhand.read())) c.94626 d.>>> print(len(fhand.read())) e.0 z. Choices are below****************************

Answer: True -The end of the file is reached after the first execution of print(len(fhand.read())). The function L() needs to read to the end-of-file inorder to count all of the characters in the file. Consequently, the second execution of print(len(fhand.read())) will have no character to count. (https://docs.python.org/3/tutorial/inputoutput.html) PL\1 and COBOL will allow and explicit rewind to the top of a file. After which, the code could be execute again. 7.4 Reading files (PFE pg 83) End Answer E E

0257--Files--True or False: Python represents the newline character as a backslash-n(\n) in string constants. For example: a. >>> stuff = 'Hello\nWorld!' b. >>> stuff c. 'Hello\nWorld!' d. >>> print(stuff) e. Hello f. World! z. Choices are below****************************

Answer: True 7.3 Text files and lines (PFE pg 81) End Answer E E

0259--Files--True or False: When a file is read using a for loop, Python splits the data in the file into separate lines using the newline character. Python reads each line through the newline and includes the newline as the last character in the line variable for each iteration of the for loop.

Answer: True 7.4 Reading files (PFE pg 82) End Answer E E

0272--Writing--True or False: When you are done writing, you have to close the file to make sure that the last bit of data is physically written to the disk.

Answer: True 7.8 Writing files (PFE pg 88) End Answer E E

0273--FileWriting--True or False: the last statement in the code below closes file "output.txt" a. >>> fout = open('output.txt', 'w') b. >>> line1 = "This here's the wattle,\n" c. >>> fout.write(line1) d. >>> fout.close()

Answer: True 7.8 Writing files (PFE pg 88) End Answer E E

0227--Indices--True or False: In the following code, the slice includes all the characters starting from index 3 thru index 21. a. data = 'aaaaGGGGGGGGKKKKKKKKEEEEEEE' b. host = data[3:22] c. Choices are below****************************

Answer: True When we slice, we extract the characters from the beginning of the left index up to but not including the the right index. (PFE pg 74) End Answer E E

0050--Variable--t/f: The maximum length of a Python variable label(name) is unlimited.

Answer: True However, convention suggest that variable name should be kept to a maximum of 79 characters. End Answer E E

0536--OOP GUI--True or False: The module "tkinter" which is included in the Standard Library makes available the basic visual building blocks(widgets) for a graphical user interface (GUI). These include buttons, labels, text entry forms, menus, check boxes, and scroll bars, among others. These building blocks are(will be) all packed inside a standard window.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 292). Wiley. Kindle Edition.

0537--OOP GUI--True or False: The following is a Tk object instantiated to represent a GUI window. >>> from tkinter import Tk >>> root = Tk()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 292). Wiley. Kindle Edition.

0539--OOP GUI--True or False: The the execution of line (c.) in the following will return a standard GUI window. a. >>> from tkinter import Tk b. >>> root = Tk() c.>>> root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 292). Wiley. Kindle Edition.

0542--OOP GUI--True or False: The "Label" method "pack()" on line (d.) determines the position of text inside the window("root" widget). a. >>> from tkinter import Tk, Label b. >>> root = Tk() c. >>> hello = Label(master = root, text = 'Hello GUI world!') d. >>> hello.pack() #hello is placed against top boundary of master e. >>> root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 293). Wiley. Kindle Edition

0543--OOP GUI--True or False: The following tkinter widget options can be used to specify the look of Label widget as well as all other tkinter widgets. text -Text to display image Image to display width -Width of widget in pixels (for images) or characters (for text); if omitted, size is calculated based on content height -Height of widget in pixels (for images) or characters (for text); if omitted, size is calculated based on content relief -Border style; possibilities are FLAT (default), GROOVE, RAISED, RIDGE, and SUNKEN, all defined in tkinter borderwidth -Width of border, default is 0 (no border) background -Background color name (as a string) foreground -Foreground color name (as a string) font -Font descriptor (as a tuple with font family name, font size, and—optionally—a font style) padx,pady -Padding added to the widget along the x- or y-axis

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 293). Wiley. Kindle Edition

0548--OOP GUI--True or False: The term "master = root" (on line (c.))is an explicit declaration of the window;the elements of "Label" will reside in "root". In this case the text "Hello GUI" will reside in the window root when root is executed. a. >>> from tkinter import Tk, Label b. >>> root = Tk() c. >>> hello = Label(master = root, text = 'Hello GUI world!') d. >>> hello.pack() #hello is placed against top boundary of master e. >>> root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 293). Wiley. Kindle Edition

0541--OOP GUI--True or False: The first argument in the "Label" constructor on line (c.), named master, specifies that the Label widget will live inside widget "root"(the window create by root). a. >>> from tkinter import Tk, Label b. >>> root = Tk() c. >>> hello = Label(master = root, text = 'Hello GUI world!') d. >>> hello.pack() #hello is placed against top boundary of master e. >>> root.mainloop()

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 293). Wiley. Kindle Edition.

0549--OOP GUI--True or False: The term "root" (on line (3.))is an implicit/positional declaration of the window "root". The first position in the argument list for the widget "Label" is reserved for the "master"(the window in which all other related widget will reside. 1) from tkinter import Tk,Label,PhotoImage,BOTTOM,LEFT,RIGHT,RIDGE 2) #GUI illustrates widget constructor options and method pack() 3) root = Tk() 4) 5) #label with text "Peace begins with a smile." 6) text = Label(root, 7) font = ('Helvetica', 16, 'bold italic'), 8) foreground='white', #letter color 9) background='black', #background color 10) padx=25, #widen label 25 pixels left and right 11) pady=10, #widen label 10 pixels up and down 12) text='Peace begins with a smile.') 13) text.pack(side=BOTTOM) #push label down 14) 15) #label with peace symbol image 16) peace = PhotoImage(file='peace.gif') 17) peaceLabel = Label(root, 18) borderwidth=3, #label border width 19) relief=RIDGE, #label border style 20) image=peace) 21) peaceLabel.pack(side=LEFT) #push label left 22) #label with smiley face image 23) smiley = PhotoImage(file='smiley.gif') 24) smileyLabel = Label(root, 25) image=smiley) 26) smileyLabel.pack(side=RIGHT) #push label right 27)

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 295). Wiley. Kindle Edition

0414--Function--True or False: Docstring, is a string that should describe what the function does and must be placed directly below the first line of a function definition. Here is how we would add docstring 'returns x**2 + 1' to our function f(): #compute x**2 + 1 and store value in res #return value of res def f(x): 'returns x**2 + 1' res = x**2 + 1 return res

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 73). Wiley. Kindle Edition.

0416--Type--True or False: The assignment of a variable to a new object does not change the original object. Instead, a new object is created, and the variable now refers to it. In fact, there is no way to change the value of the original object. This illustrates an important feature of Python: Python int objects cannot be changed. Integer objects are not the only objects that cannot be modified. Types whose objects cannot be modified are called immutable. All Python number types (bool, int, float, and complex) are immutable.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 75). Wiley. Kindle Edition.

0412--Function--True or False: In general, when calling and executing a function, the function will not modify the value of any variable passed as a function argument if the variable refers to an immutable object. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 80). Wiley. Kindle Edition.

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 80). Wiley. Kindle Edition.

0026--Function--True or False: In general, when the argument sep=<some string> is added to the arguments of the print() function, the string <some string> will be inserted between the values: >>>print(n, r, name, sep=',') 5, 1.66666666667, Ida >>>print(n, r, name, sep='\n') 5 1.66666666667 Ida Choices below: True False

Answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 99). Wiley. Kindle Edition.

0159--Definition--t\f--The flow of execution is the order in which statements are executed during a program run.

Answer: True The order in which statements are executed during a program run. (PFE pg 53) End Answer E E

0158--Function--t\f: Dot notation is the syntax for calling a function in another module by specifying the module name followed by a dot (period) and the function name.

Answer: True The syntax for calling a function in another module by specifying the module name followed by a dot (period) and the function name. (PFE pg 53) End Answer E E

0142--Function--True or False: The empty parentheses after the function name indicate that this function doesn't take any arguments.

Answer: True (PFE pg 47) End Answer E E

0418--Function--True or False: The method count(), when called on a string with string input argument target, returns the number of times target appears as a substring of the string. For example: >>>

Answer: True --message.count('top secret') >>> message = '''This message is top secret and should not be divulged to anyone without top secret clearance ''' >>> >>> message.count('top secret') 2 >>> Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 96). Wiley. Kindle Edition.

0039--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "T"? 1.turn 2.track 3.try 4.true 5.trans

Answer: True;try End Answer E E

0150--Function--Yes or No:Are variables legal function arguments?

Answer: Yes (PFE pg 50) You can also use a variable as an argument: >>> michael = 'Eric, the half a bee.' >>> print_twice(michael) Eric, the half a bee. Eric, the half a bee. End Answer E E

0294--ListFunctions--MultipleChoice: What will the following code return? a.>>> t = ['a', 'b', 'c', 'd', 'e', 'f'] b. >>> del t[1:5] c. >>> print(t) z. Choices are below**************************** 1. ['a', 'f'] 2. ['a', 'b', 'c', 'd', 'e', 'f'] 3. ['b', 'c', 'd', 'e'] 4. 'a', 'f'

Answer: ['a', 'f'] - the slice selects all the elements up to, but not including, the second index. >>> >>> t = ['a', 'b', 'c', 'd', 'e', 'f'] >>> del t[1:5] >>> print(t) ['a', 'f'] 8.7 Deleting elements (PFE pg 95) End Answer E E

0195--Slice--MultipleChoice: What is the value assigned to the variable letter? a. >>> fruit = 'banana' b. >>> letter = fruit[1] c. Choices are below**************************** 1. banana 2. 1 3. b 4. a

Answer: a (PFE pg 67) End Answer E E

0133--Function--Essay: The module function random.random will return a number greater than _____a.__ but less than ___b.___

Answer: a. 0.0; b. 1.0 End Answer E E

0203--Indices--MultipleChoice: Based on the following code, what will the print() yield? a. >>> s = 'Monty Python' b. >>> print(s[0:5]) c. _______a.________ d. >>> print(s[6:12]) e. _____b.__________ f. Choices are below**************************** 1. (a.) mon 2. (a.) Monty 3. (b.) hoty 4. (b.) Python 5. none of the above

Answer: a. Monty; b. Python The operator--[0:5] and [6:12] -- returns the part of the string from the "n-th" character to the "m-th" character, including the first but excluding the last. (PFE pg 69) End Answer E E

0127--Function--Essay: The module name is a reference to a___ (a.)____ that contains ____(b.)____ and ____c.___ .

Answer: a. file ; b. functions; c. variables The import statement creates a module object that contains the functions and variables defined in the module(file). (PFE pg 45) End Answer E E

0134--Function--MultipleChoice: The module function random.randint(low,high) takes two arguments of type __a.__ and return a number of type __b.__ that is greater than__c.__by less than ___d.__ . Choose all apply: 1. integer 2.floating point 3. string 4. low 5. high

Answer: a. integer; b. integer; c. low; d. high (PFE pg 46) End Answer E E

0128--Function--MultipleChoice: To access one of the functions contained in a module object, you have to specify the name of the ___a___ and the name of the ___b.___, using ___c___ notation. Choose all those that apply: 1. return 2. path 3. module 4. dot 5. function

Answer: a. module; b. function; c. dot -To access one of the functions, you have to specify the name of the module and the name of the function, separated by a dot (also known as a period). This format is called dot notation. (PFE pg 45) >>> ratio = signal_power / noise_power >>> decibels = 10 * math.log10(ratio) ____________________________________ >>> radians = 0.7 >>> height = math.sin(radians) _______________________________________ >>> degrees = 45 >>> radians = degrees / 360.0 * 2 * math.pi >>> math.sin(radians) 0.7071067811865476 ______________________________________ >>> math.sqrt(2) / 2.0 0.7071067811865476 End Answer E E

0025--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "A"? 1. advance 2. and 3. add 4. available 5. as 6. assert

Answer: and; as; assert End Answer E E

0113--The expression in parentheses--type(32)-- is called the____________of the function.

Answer: argument A value or variable that we pass to the function as input to the computations of the function. (PFE pg 43) End Answer E E

0084--Conditional--Essay: How many statements must appear in the body or indent code block of an "if" procedure" if the procedure is to execute without a traceback?

Answer: at least one statement must inhabit the indented code block. -at least one -one End Answer E E

0171--Function--MultipleChoice: What is the purpose of the "def" keyword in Python? 1. It is slang that means "the following code is really cool" 2. It indicates the start of a function 3. It indicates that the following indented section of code is to be stored for later 4. b and c are both true 5. None of the above

Answer: b) It indicates the start of a function; c) It indicates that the following indented section of code is to be stored for later (PFE pg 54) End Answer E E

0074--For what data type does True and False belong?

Answer: boolean End Answer E E

0106--Conditional--MultipleChoice: A statement that consists of a header and a body. The header ends with a colon (:). The body is indented relative to the header. 1. comparison operator 2. condition 3. boolean expression 4. compound statement

Answer: compound statement (PFE pg 40) End Answer E E

0105--Conditional--MultipleChoice: The boolean expression in a conditional statement that determines which branch is executed. 1. comparison operator 2. condition 3. boolean expression 4. body

Answer: condition (PFE pg 40) End Answer E E

0104--Conditional--MultipleChoice: A statement that controls the flow of execution depending on some condition. 1. comparison operator 2. conditional 3. boolean expression 4. body

Answer: conditional statement (PFE pg 40) End Answer E E

0026--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "C"? 1. cover 2. control 3. continue 4. contact 5. class

Answer: continue; class End Answer E E

0235--Files--MultipleChoice--A variable used to count something is usually initialized to zero and then incremented. 1. format sequence 2. format string 3. counter 4.format operator

Answer: counter (PFE pg 76) End Answer E E

0428--Function--What will the following code return?: print('{}, {} {}, {} at {}:{}:{}'.format(weekday, month, day, year, hour, minute, second))

Answer: current day of week, current date, current time Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 101). Wiley. Kindle Edition.

0027--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "D"? 1. dap 2. drv 3. def 4. dep 5. del

Answer: def; del End Answer E E

0129--Definition--MultipleChoice: Given the same inputs, most computer programs generate the same outputs every time, so they are said to be ________. 1. model 2. artificially intelligent 3. deterministic 4. dumb

Answer: deterministic (PFE pg 46) End Answer E E

0028--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "E"? 1. end 2. easy 3. except 4. enter 5. elif 6. elfa 7. else

Answer: else; except;elif End Answer E E

0236--Files--MultipleChoice--A string with no characters and length 0, represented by two quotation marks. 1. format sequence 2. empty string 3. counter 4.format operator

Answer: empty string (PFE pg 76) End Answer E E

0132--Conditional--Essay: Create a one line compound statement from the following: a. for i in range(10): b. .....x = random.random() c. .....print(x)

Answer: for i in range(10): x = random.random(); print(x) https://docs.python.org/3.4/reference/compound_stmts.html End Answer E E

0237--Format--MultipleChoice--An operator, %, that takes a format string and a tuple and generates a string that includes the elements of the tuple formatted as specified by the format string. 1. format sequence 2. empty string 3. counter 4.format operator

Answer: format operator (PFE pg 76) End Answer E E

0238--Files--MultipleChoice--A sequence of characters in a format string, like %d, that specifies how a value should be formatted. 1. format sequence 2. empty string 3. counter 4.format operator

Answer: format sequence (PFE pg 76) End Answer E E

0240--Files--MultipleChoice--A string, used with the format operator, that contains format sequences. 1. format sequence 2. empty string 3. counter 4.format string

Answer: format string (PFE pg 77) End Answer E E

0112--Functions--Essay: A named sequence of statements that performs a computation.

Answer: function example- >>> type(32) <class 'int'>(PFE pg 43) End Answer E E

0243--Files--MultipleChoice--The property of a sequence whose items cannot be assigned. 1. flag 2. invocation 3. immutable 4.format string

Answer: immutable (PFE pg 77) End Answer E E

0125--Function--Essay: What code(statement) would we write to import the entire Python math module?

Answer: import math Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into other modules or into the main module(https://docs.python.org/3/tutorial/modules.html?highlight=module%20object) End Answer E E

0212--Operators--Essay: The keyword______is a boolean operator that takes two strings and returns True if the first appears as a substring in the second

Answer: in (PFE pg 71) End Answer E E

0244--Files--MultipleChoice--An integer value used to select an item in a sequence, such as a character in a string. 1. flag 2. invocation 3. immutable 4. index

Answer: index (PFE pg 77) End Answer E E

0118--Function--MultipleChoice: What function will convert the string "32" into an integer? 1. min() 2. max() 3. len() 4. int()

Answer: int('32') Type conversion functions (PFE pg 44) End Answer E E

0033--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "I"? 1. insert 2. in 3. int 4. is 5. if 6. import

Answer: is;in if;import End Answer E E

0189--Loop--MultipleChoice: What is the value of iteration variable(itervar) and the total variable when the for loop terminates? a. total = 0 b. for itervar in [3, 41, 12, 9, 74, 15]: c. ....total = total + itervar d. print('Total: ', total) e. Choices are below**************************** 1.itervar = 0, total = 0 2.itervar = 6, total = 153 3.itervar = 15, total = 154 4.itervar = 3, total = 153

Answer: itervar = 15, count = 154 In this loop we do use the iteration variable. Instead of simply adding one to the count as in the previous loop, we add the actual number (3, 41, 12, etc.) to the running total during each loop iteration. If you think about the variable total, it contains the "running total of the values so far". So before the loop starts total is zero because we have not yet seen any values, during the loop total is the running total, and at the end of the loop total is the overall total of all the values in the list. As the loop executes, total accumulates the sum of the elements; a variable used this way is sometimes called an accumulator. (PFE pg 62) End Answer E E

0034--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "L"? 1. like 2. look 3. lambda 4. loop 5. luck

Answer: lambda End Answer E E

0200--Slice--MultipleChoice: What is the value of the variable last and the variable nxt_ based on the code below? a. >>> fruit = 'banana' b. >>> last = fruit[-1] c. >>> nxt_ = fruit[-2] d. Choices are below**************************** 1. last == 'a' 2. last == 'n' 3. last == 'b' 4. nxt_ == 'n' 5. nxt_ == 'a'

Answer: last == 'a'; nxt_ == 'n' The expression fruit[-1] yields the last letter, fruit[-2] yields the second to last, and so on. (PFE pg 68) End Answer E E

0246--Files--MultipleChoice--A function that is associated with an object and called using dot notation. 1. item 2. invocation 3. immutable 4.method

Answer: method (PFE pg 77) End Answer E E

0109--Conditional--MultipleChoice: A conditional statement that appears in one of the branches of another conditional statement. 1. nested conditional 2. guardian pattern 3. boolean expression 4. compound pattern

Answer: nested conditional (PFE pg 40) End Answer E E

0253--Exercise 6: Read the documentation of the string methods at https://docs.python.org/library/stdtypes.html#string-methods You might want to experiment with some of them to make sure you understand how they work. strip and replace are particularly useful. The documentation uses a syntax that might be confusing. For example, in find(sub[, start[, end]]), the brackets indicate optional arguments. So sub is required, but start is optional, and if you include start, then end is optional.

Answer: not done (PFE pg 77) End Answer E E

0130--Definition--MultipleChoice: Pseudorandom numbers generated by a deterministic computation are ___a.__ random numbers. 1. not truly 2. perfect 3. distinguished 4. red and blue

Answer: not truly Pseudorandom numbers are not truly random because they are generated by a deterministic computation, but just by looking at the numbers it is all but impossible to distinguish them from random. (PFE pg 46) End Answer E E

0035--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "N"? 1. not 2. nor 3. nonlocal 4. none 5. neither

Answer: not;NONE;nonlocal; End Answer E E

0247--Files--MultipleChoice--Something a variable can refer to. For now, you can use __?__ and "value" interchangeably. 1. object 2. invocation 3. immutable 4.method

Answer: object (PFE pg 77) End Answer E E

0036--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "O"? 1. or 2. occur 3. orb 4. open 5. obv

Answer: or End Answer E E

0143--Function--MultipleChoice: What is the syntax for calling(executing) the user defined function "print_lyrics" ? 1. go print_lyrics() 2. call print_lyrics() 3. print_lyrics()

Answer: print_lyrics() (PFE pg 48) End Answer E E

0248--Files--MultipleChoice--A pattern of traversal that stops when it finds what it is looking for. 1. object 2. invocation 3. search 4.method

Answer: search (PFE pg 77) End Answer E E

0249--Files--MultipleChoice--An ordered set; that is, a set of values where each value is identified by an integer index. 1. object 2. invocation 3. search 4.sequence

Answer: sequence (PFE pg 77) End Answer E E

0202--Indices--MultipleChoice: A python string segment of a larger string is called a ________. 1. mini-string 2. substring 3. subset 4. thread 5. slice

Answer: slice (PFE pg 69) Note! The author sometimes refers to a slice as a substring (see PFE 73). End Answer E E

0250--Files--MultipleChoice--A part of a string specified by a range of indices. 1. slice 2. invocation 3. search 4.sequence

Answer: slice (PFE pg 77) End Answer E E

0198--Slice--Essay: What is the value of-- >>> letter = fruit[1.5]--- the variable "letter" based on >>> fruit = banana'?

Answer: traceback The data type of the index must be integer. However, the integer can be represented by any expression that yields an integer. (PFE pg 67) End Answer E E

0199--Slice--MultipleChoice: What is the value of the variable "last" based on the code below? a. >>> fruit = 'banana' b. >>> length = len(fruit) c. >>> last = fruit[length] d. Choices are below**************************** 1. a 2. n 3. trackback 4. none of the above

Answer: traceback The reason for the IndexError is that there is no letter in "banana" with the index 6. Since we started counting at zero, the six letters are numbered 0 to 5. To get the last character, you have to subtract 1 from length. (PFE pg 67) End Answer E E

0251--Files--MultipleChoice--To iterate through the items in a sequence, performing a similar operation on each. 1. slice 2. invocation 3. search 4. traverse

Answer: traverse (PFE pg 77) End Answer E E

0284--Loop--True or False: The body of a for loop will not execute when the member list is empty

Answer: true (PFE pg 93) End Answer E E

0322--(b) is a tuple. Is the statement >>> a, b = b, a equivalent based on the following: a. >>> a = b b. >>> b = a z. Choices are below**********************

Answer: true Both sides of this statement are tuples, but the left side is a tuple of variables; the right side is a tuple of expressions. Each value on the right side is assigned to its respective variable on the left side. All the expressions on the right side are evaluated before any of the assignments. The number of variables on the left and the number of values on the right must be the same: 10.3 Tuple assignment (PFE pg 120) End Answer E E

0320--Tuple--True are False: Based on the following code, x equals 'have' and y equals 'fun': a. >>> m = [ 'have', 'fun' ] b. >>> x, y = m z. Choices are below**********************

Answer: true It is not magic, Python roughly translates the tuple assignment syntax to be the following: >>> m = [ 'have', 'fun' ] >>> x = m[0] >>> y = m[1] 10.3 Tuple assignment (PFE pg 120) End Answer E E

0319--Tuple--True or False : The following describes the DSU pattern: -Decorate a sequence by building a list of tuples with one or more sort keys preceding the elements from the sequence, -Sort the list of tuples using the Python built-in sort, and -Undecorate by extracting the sorted elements of the sequence.

Answer: true 10.2 Comparing tuples (PFE pg 118) End Answer E E

0315--Dictionary Method--True or False: Which ones of the following are True?: 1. Programmer can make a list of dictionary keys using the key method. For example: a. >>>counts = { 'chuck' : 1 , 'annie' : 42, 'jan': 100} b. >>>lst = list(counts.keys()) c. >>>print(lst) d. >>>lst.sort() e. >>>for key in lst: f. ...............print(key, counts[key]) g. .....#output: h. ..........['jan', 'chuck', 'annie'] j. ..........annie 42 k. ..........chuck 1 l. ...........jan 100 z. Choices are below****************************

Answer: true 9.3 Looping and dictionaries (PFE pg 111) End Answer E E

0318--Tuple--true or false : The comparison operators work with tuples and other sequences. Python starts by comparing the first element from each sequence. If they are equal, it goes on to the next element, and so on, until it finds elements that differ. Subsequent elements are not considered (even if they are really big). a. >>> (0, 1, 2) < (0, 3, 4) b. True c. >>> (0, 1, 2000000) < (0, 3, 4) d. True z. Choices are below**********************

Answer: true 10.2 Comparing tuples (PFE pg 118) End Answer E E

0088--Conditional--Essay: "Chained conditional" procedures are used to address situations where more than________________outcome are possible..

Answer: two End Answer E E

0305--Exercise 2: Figure out which line of the above program is still not properly guarded. See if you can construct a text file which causes the program to fail and then modify the program so that the line is properly guarded and test it to make sure it handles your new text file.

Answer: undone 8.14 Debugging (PFE pg 102) End Answer E E

0151--Function--MultipleChoice: A function that return the Keyword "None" is a __a__ function. 1. cancel 2. void 3. null 4. joke

Answer: void (PFE pg 51) Void functions might display something on the screen or have some other effect, but they don't have a return value. If you try to assign the result to a variable, you get a special value called None. End Answer E E

0040--Keyword--Multiple Choice: What Python interpret Keywords/Reserved words begin with "W"? 1.wake 2.way 3.with 4.wage 5.while

Answer: with;While End Answer E E

0041--Keyword--Multiple Choice: What Python interpret Keywords/Reserve words begin with "Y"? 1.yield 2.yet 3.yolk 4.yell 5.yes

Answer: yield End Answer E E

0197--Slice--Essay: What is the index position of the character "b" in >>> fruit = 'banana'?

Answer: zero For most people, the first letter of "banana" is "b", not "a". But in Python, the index is an offset from the beginning of the string, and the offset of the first letter is zero. (PFE pg 67) End Answer E E

0323--Tuple--True of False: Based on the following code, a equals 1 and b equals 2: a. >>> a, b = 1, 2, 3 z. Choices are below**********************

Answer:False The number of variables on the left and the number of values on the right must be the same: >>> a, b = 1, 2, 3 ValueError: too many values to unpack 10.3 Tuple assignment (PFE pg 121) End Answer E E

0044--What are the categories of Python operators?

Arithmetic; Comparison; Assignment; Bitwise; Logical; Membership; Identity End Answer E E

0350--What is the output of the following code? a.>>>for char in 'PYTHON STRING': b........ ...if char == ' ': c...................break d............print(char, end='') e........ ...if char == 'O': f....................continue z. Choices are below********************** 1. PYTHON 2.PYTHONSTRING 3. PYTHN 4.STRING

1. PYTHON https://www.programiz.com/node/664/quiz-results/175787/view

0341--What is the output of the following code? a. >>>numbers = [2, 3, 4] b. >>>print(numbers) z. Choices are below********************** 1. 2, 3, 4 2. 2 3 4 3. [2, 3, 4] 4. [2 3 4]

3. [2, 3, 4] https://www.programiz.com/node/720/quiz-results/175483/view

0544--If you print the function object with its parentheses, as show below, what information will the print function return? >>> def print_lyrics(): >>> print("I'm a lumberjack, and I'm okay.") >>> print('I sleep all night and I work all day.') >>> print(print_lyric()) 1. the source code 2. the machine code 3. <function print_lyrics at 0xb7e99e9c> 4. print("I'm a lumberjack, and I'm okay.") print('I sleep all night and I work all day.') 5. traceback

Answer (4.) -- (PFE pg 48)

0213--Operators--MultipleChoice: Which of the following statements will return True? 1. 'a' in 'banana' 2. 'seed' in 'banana' 3. 'ban' in 'banana' 4. 'lake' in 'banana'

Answer: 1. True; 2. False; 3. True; 4. False (PFE pg 71) End Answer E E

0126--Function--MultipleChoice: Import statement creates a ______. 1. return 2. variable 3. module object 4. traceback

Answer: module object (PFE pg 45) End Answer E E

0531--Type--What value will the Python function "type (x )" return?

Data type. For the parameter "x', type() will return the data type--string(str), integer(int), floating point(float) of the value held in "x'.

0303--Exercise 1: undone Write a function called chop that takes a list and modifies it, removing the first and last elements, and returns None. Then write a function called middle that takes a list and returns a new list that contains all but the first and last elements.

Exercise 1: 8.13 List arguments (PFE pg 101) End Answer E E

0391--Tuple--True or False: () is what the following code returns; >>> t = tuple('lupins') >>> print(t)

False - - # An empty tuple >>> empty_tuple = () >>> print (empty_tuple) () 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0370--Regex--Exercise 1: Write a simple program to simulate the operation of the grep command on Unix. Ask the user to enter a regular expression and count the number of lines that matched the regular expression: $ python grep.py Enter a regular expression: ^Author mbox.txt had 1798 lines that matched ^Author $ python grep.py Enter a regular expression: ^X mbox.txt had 14368 lines that matched ^X- $ python grep.py Enter a regular expression: java$ mbox.txt had 4175 lines that matched java$

Keyanswer: undone 11.9 Exercises (PFE pg 139) End Answer E E

0080--Conditional--t\f: The following code will execute without creating a traceback?: var = 100 if ( var == 100 ) : print("Value of expression is 100") print("Good bye!")

No. -- the body of the if statement is not indented. >>> var = 100 >>> if ( var == 100 ) : print("Value of expression is 100") ... print("Good bye!") File "<stdin>", line 2 print("Good bye!") ^ SyntaxError: invalid syntax End Answer E E

0064--Function--Essay: When input() is called what happens to program execution?

Program execution stop until a string value is input to the terminal and the ENTER/RETURN key is pressed. End Answer E E

0053--Error-MultipleChoice: Define semantic error. 1. Code that triggers a malicious virus. 2. A code error due to inappropriate design . 3. The code returns the wrong value without producing an error message.

The code returns the wrong value without producing an error message. End Answer E E

0076--Operators--Essay: Python has how many logical operators?

Three End Answer E E

0093--Conditional--t\f: Yes or No: Nested "if" conditions are allowed within an else clause?

True End Answer E E

0381--Tuple--True or False: the following code will create a tuple: >>> t =( 'a', 'b', 'c', 'd', 'e')

True - 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0395--Tuple--True or False: The following code will reassign the content of tuple "t": >>> t = ('a', 'b', 'c', 'd', 'e') >>> t = ('A',) + t[1:] >>> print(t) ('A', 'b', 'c', 'd', 'e')

True - You can't modify the elements of a tuple, but you can replace one tuple with another: 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0073--Boolean--Essay: What is returned by the statement 5 == 5?

True:A boolean expression is an expression that is either true or false. The operator ==, which compares two operands and produces True if they are equal and False otherwise.(PFE pg 31) End Answer E E

0089--Conditional--t\f: The following code will produce a traceback? x=10 y=9 if x < y: .....print('x is less than y') else: .....print('x and y are equal') elif x > y: .....print('x is greater than y')

Yes. If there is an else clause, it has to be at the end, but there doesn't have to be one. (PFE pg 34) End Answer E E

0483--Namespace--essay: What will the following code return?: a. from userRout import prtnme b. #def prtnme(): c. print('My name is {}'.format(__name__)) d. prtnme() e. print('My name is {}'.format(__name__)) f. a = 10 g. print("Attribute 'a' has an object value of {}.".format(a))

answer: 1. prtnme() ---> My name is userRout 2. print('My name is {}'.format(__name__)) ---> My name is __main__ 3. print("Attribute 'a' has an object value of {}.".format(a)) ---> Attribute 'a' has an object value of 10. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 226). Wiley. Kindle Edition.

0443--Function--What does the following code return?: >>> '{:6.2f}'.format(5/ 3)

answer: ' 1.67' Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0437--Function--Match >>> n = 10 >>> '{:b}'.format(n) Choices below: 1. '\n' 2. 'a' 3. '10' 4. '1010' answer: Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

answer: 4 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0358--Regex--What will the following code return?: a. line = '<[email protected]>;' b. x = re.findall('[a-zA-Z0-9]\S+@\S+[a-zA-Z]', line) z. Choices are below********************** 1. '<[email protected]>;' 2. '[email protected];' 3. '<[email protected]>' 4. '[email protected]' reads as: 1. findall() -- find all the substrings of "line" based on the search criteria 2. '[a-zA-Z0-9]' -- find a substring where the first [the search expression is configure to find one character not multiple characters; this expression seem equivalent to startswith() ] character begins with a lower case alphabet , upper case alphabet or digit zero through nine. 3. \S+ -- if (2.) above is True find the adjacent characters[the ones next to the one found in (2.)] that are non-whitespace up and until the character found is "@" 4. \S+ -- if (3.) above is True find the adjacent characters[the ones following the "@" found in (3.)] that are non-whitespace up and until the last non-whitespace character. 5. '[a-zA-Z0-9]' -- if (3.) above is True find a substring where the last[the search expression is configure to find one character not multiple characters; this expression seem equivalent to endswith() ] character ends with a lower case alphabet , upper case alphabet or digit zero through nine.

answer: 4. '[email protected]' 11.2 Extracting data using regular expressions (PFE pg 132) End Answer E E

0497--File--Multiple: The statement ""outfile = open('test.txt', 'w')" will: 1. open a file in write mode 2. create the file 'test.txt if it does not exist 3. erase the content of 'test.txt' if the file already exists 4. place the file cursor at the beginning of the file 5. all the above

answer: 5 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 115). Wiley. Kindle Edition.

0515--Dictionaries--Multiple choice: Provide the number of the correct statements: 1. A dictionary can be modified to contain a new (key, value) pair: >>> days['Fr'] = 'friday' 2. Mutability implies that dictionaries have dynamic size. 3. The dictionary can be modified so that an existing key refers to a new value: >>> days['Fr'] = 'Friday' 4. An empty dictionary can be defined using the default dict() constructor or simply as: >>> d = {} 5. all the above

answer: 5 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 168). Wiley. Kindle Edition.

0434--Match Integer Presentation type o Choices below: 1. Outputs the number in decimal notation (default) 2. Outputs the number in base 16, using lowercase letters for the digits above 9 3. Outputs the number in base 16, using uppercase letters for the digits above 9 4. Outputs the number in binary 5. Outputs the number in base 8 6. Outputs the Unicode character corresponding to the integer value

answer: 5 Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 104). Wiley. Kindle Edition.

0525--Dictionaries--Yes or No: Will the following code properly populate the dictionary "phonebooK"? >>> phonebook = {['Anna','Karenina']:'(123)456-78-90', ['Yu', 'Tsun']:'(901)234-56-78', ['Hans', 'Castorp']:'(321)908-76-54'}

answer: No Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 176). Wiley. Kindle Edition.

0362--Regex--When you are using findall(), parentheses indicate that you want to extract the portion of the string related to that part of the regular expression that is enclosed in parentheses. Does this description properly characterize the extract operation in the following code?: re.findall('^X\S*: ([0-9.]+)', line)

answer: T 11.3 Combining searching and extracting (PFE pg 134) End Answer E E

0360--Regex--True or False: Inside the regular expression square brackets "[0-9.]", the period matches an actual period (i.e., it is not a wildcard between the square brackets).

answer: True 11.3 Combining searching and extracting (PFE pg 132) End Answer E E

0366--Regex--True or False: Using regular expressions we can indicate that we want to simply match a character by prefixing that character with a backslash. For example, we can find the dollar sign"$" and the money amounts with the following regular expression? a. import re b. x = 'We just received $10.00 for cookies.' c. y = re.findall('\$[0-9.]+',x)

answer: True 11.4 Escape character (PFE pg 136) + Matches 1 or more repetitions of the regular expression immediately preceding it. Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 389). Wiley. Kindle Edition. End Answer E E

0478--Namespace--True or False:The following code will append a directory to the module search path >>> import sys >>> sys.path.append('/Users/me')

answer: True Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 225). Wiley. Kindle Edition.

0501--Execution Control--true or false: Given that the number of loop iterations is unknown, we would choose to use a while loop rather than a for loop.

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 148). Wiley. Kindle Edition.

0503--Execution Control--true or false: The break statement does not affect the outer for loop, which will iterate through all the rows of the table regardless of whether the break statement has been executed. def before0(table): '''prints values in 2D list of numbers t as a 2D table; only values in row up to first 0 are printed ''' ........for row in table: ................for num in row: #inner for loop ........................if num == 0: #if num is 0 ...............................break #terminate inner for .......................print(num, end='') #otherwise print num 1 ..............print() #move cursor to next line - - - - - -

answer: true Perkovic, Ljubomir. Introduction to Computing Using Python: An Application Development Focus, 2nd Edition (Page 150). Wiley. Kindle Edition.

0100--DataType--Essay: An expression whose value(data type) is either True or False.

boolean expression (PFE pg 39) End Answer E E

0101--Conditional--MultipleChoice: One of the alternative sequences of statements in a conditional statement. 1. comparison operator 2. branch 3. boolean expression 4. body

branch (PFE pg 39) End Answer E E

0317C--Match the word hash function to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

c./3. - hash function - A function used by a hashtable to compute the location for a key. 9.6 Glossary (PFE pg 115) End Answer

0102--A conditional statement with a series of alternative branches. 1. comparison operator 2. chained conditional 3. boolean expression 4. body

chained conditional: "elif" statements(PFE pg 40) End Answer E E

0317D--Match the word histogram to its definition: 1. Another name for a key-value pair. 2. The representation of the mapping from a key to a value. 3. A function used by a hashtable to compute the location for a key. 4. A set of counters 5. When there are one or more loops "inside" of another loop. The inner loop runs to completion each time the outer loop runs once. 6. A mapping from a set of keys to their corresponding values. 7. An object that appears in a dictionary as the first part of a key-value pair. 8. A way of performing a computation. 9. An object that appears in a dictionary as the second part of a key-value pair. This is more specific than our previous use of the word "value". 10. The algorithm used to implement Python dictionaries. 11. A dictionary operation that takes a key and finds the corresponding value.

d./4. - histogram- A set of counters. 9.6 Glossary (PFE pg 115) End Answer

0310E--Match the word index to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

e./4. index-An integer value that indicates an element in a list. 8.15 Glossary (PFE pg 105) End Answer

0090--Conditional--Essay: "Chained conditional" procedures are associated with the keyword and clause _______________ .

elif End Answer E E

0316--incomplete 1.line.translate(str.maketrans(fromstr, tostr, deletestr)) Replace the characters in fromstr with the character in the same position in tostr and delete all characters that are in deletestr. The fromstr and tostr can be empty strings and the deletestr parameter can be omitted. 2. >>> import string >>> string.punctuation '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' 3.

incomplete 9.4 Advanced text parsing (PFE pg 111) End Answer E E

0310J--Match the word object to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

j./9. object- Something a variable can refer to. An object has a type and a value. 8.15 Glossary (PFE pg 105) End Answer

0310K--Match the word reference to its definition: 1. A character or string used to indicate where a string should be split. 2.A sequence of values 3.Being the same object (which implies equivalence). 4. An integer value that indicates an element in a list. 5. The sequential accessing of each element in a list. 6. One of the values in a list (or other sequence); also called items. 7. A list that is an element of another list. 8. Having the same value. 9. Something a variable can refer to. An object has a type and a value. 10. A circumstance where two or more variables refer to the same object. 11. The association between a variable and its value.

k./11. reference-The association between a variable and its value 8.15 Glossary (PFE pg 105) End Answer

0329--True or Fasle: Because tuples are hashable and lists are not, if we want to create a composite key to use in a dictionary we must use a tuple as the key.

keyanswer: True 10.7 Using tuples as keys in dictionariess (PFE pg 124) End Answer E E

0017--Tuple-- True or False: the following code will assign "A" to the first element of the tuple "t": >>> t[0] = 'A'

keyanswer: false 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0003---3. True or False: the following code will create a tuple: >>> t = 'a', 'b', 'c', 'd', 'e'

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0005--Tuple--True or False: the following code will create a tuple: >>> t =( 'a', )

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0006--Tuple--True or False: the following code will create a tuple: >>> t = 'a',

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0334--Exercise 2: This program counts the distribution of the hour of the day for each of the messages. You can pull the hour from the "From" line by finding the time string and then splitting that string into parts using the colon character. Once you have accumulated the counts for each hour, print out the counts, one per line, sorted by hour as shown below. python timeofday.py Enter a file name: mbox-short.txt 04 3 06 1 07 1 09 2 10 3 11 6 14 1 15 2 16 4 17 2 18 1 19 1

keyanswer: undone (PFE pg 126) End Answer E E

0278--Exercise 1: Write a program to read through a file and print the contents of the file (line by line) all in upper case. Executing the program will look as follows:

undone 7.11 Exercises (PFE pg 89) End Answer E E

0009-- Tuple--True or False: the following code will create a tuple: >>> t = tuple()

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0010--Tuple-- True or False: the following code will create a tuple: >>> t = tuple('lupins')

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0011--Tuple-- True or False: ('l', 'u', 'p', 'i', 'n', 's') is what the following code returns: >>> t = tuple('lupins'); >>> print(t)

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0013--Tuple--True or False: Tuples are immutable.

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0015--Tuple-- True or False: tuple() is a built-in function.

keyanswer: true 10.1 Tuples are immutable (PFE pg 118) End Answer E E

0068--Comments--Essay: Where on a line are comments allowed to start?

anywhere End Answer E E


Set pelajaran terkait

*possible help/practice exams 2*

View Set

SIMULATED TEST QUESTIONS - PRACTICE EXAM 3 - (please feel free to submit edits/corrections to Mike!)

View Set

Final exam Digital and social media

View Set

Administrative Procedures: Chapter 12

View Set

Bus Policy & Stategy Exam 2 (1-25)

View Set