Cis 122 Study

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

Identify the correct syntax to escape a single quotation mark as a special character within a Python string. 'G\nDay Mate!' 'G\'Day Mate!' 'G'Day Mate!' "G'Day Mate!"

'G\'Day Mate!'

Identify the correct value of result given the following code. result = 'Oregon'[3:] 'ego' 'gon' '' or empty string 'Ore'

'gon'

Identify the correct value of result given the following code. result = 'Oregon'[::-1] 'r' 'nogerO' 'O' 'n'

'nogerO'

Identify the output in the following code. def repeat(data, count, spacer = '_'): result = '' for i in range(count): result = result + data if i < count - 1: result = result + spacer return result repeat('s', 3) 'sss' 's s s' 's_s_s_' 's_s_s'

's_s_s'

Identify the single answer that is the Python integer division operator. // / divide #

//

Identify the output from the following Python function. def foo(): for i in range(3): print(i * 3, end = '') 369 036 0123 0246

036

Identify the ASCII decimal value of the control character \n. 10 CR LF 13

10

Identify the single answer that is a VALID Python floating point number. 'Eugene' 3 math.pi 3.14

3.14

Identify the printed output of calling the following Python function with the specified arguments. def volume(length, width, height): return length * width * height print(volume(height=5, width=4, length=3)) 543 60 12 345

60

Identify the final value of word_cnt in the following Python code. s = "Peter Piper picked a peck of pickled peppers" word_cnt = 0 for chr in s: if chr == ' ': word_cnt = word_cnt + 1 0 8 7 10

7

Identify the invalid Python relational operator. = == <= !=

=

Identify the correct term given to an object with more than one variable reference. Alias Use case List Equivalent

Alias

Identify the problem with the following code. info = 'ABC' info[0] = 'X' Strings are immutable All answers are true The code will generate a syntax error A string object does not support item assignment

All answers are true

Identify the name given to num within the parentheses in the following Python code. def square(x): # square codenum = 10 square(num) Keyword Argument Parameter Function

Argument

Identify the problem with the following Python code. fin.close() fin.readline() The code contains no problems Cannot read from a closed file File name must be specified with readline() method Close() method not supported by file object

Cannot read from a closed file

Identify the name given to the Python operator that combines strings. Concatenation operator Arithmetic operator Combination operator String operator

Concatenation operator

Identify the term that promotes reusability, self-documentation, functionality isolation and easier testing with less negative side effects. Composition Generalization Encapsulation Interface

Encapsulation

Identify the benefits of functions. Select all that apply. Composition Encapsulation Reusability Abstraction Testing Organization

Encapsulation Reusability Abstraction Testing Organization

Closing a file does NOT reset the file object file pointer. True False

False

Code documentation and white space have no value when coding. True False

False

Drawing with Python Turtle Graphics always begins in the top-left corner of the drawing window. True False

False

Function parameters are local variables that exist within the function body and outside the function body. True False

False

Identify the correct value of result given the following code. result = not (len('Oregon') != 3) 6 3 True False

False

Python code can ONLY be executed from IDLE. True False

False

Python conditional statements must always have an ELSE clause. True False

False

Python has an established coding style that must be rigidly followed to ensure correction execution of your program code. True False

False

Python lists are immutable. True False

False

The Python in operator can NOT be used to search for one string within another string True False

False

The following code will produce a syntax error and will not execute. result = 'A' < 'B' True False

False

The readline() method does NOT read any line ending characters. True False

False

The strip() method removes all leading, trailing and embedded white space. True False

False

The variable result is not required to be initialized before executing in the following line of code. result = result + 1 True False

False

When using multiple Python conditional ELIF clauses in a single conditional statement, all conditional expressions that are True will execute their conditional code. True False

False

You must always use the file readline() method whenever using the for in syntax to read file contents. True False

False

Identify the Python element that should always have a docstring. Variable Conditional Function Loop

Function

Select the correct order of the steps of computational thinking.

Identify a problem and divide a problem into smallest possible tasks Look for patterns related to the problem that make solving the process easier Express the patterns and small tasks in simplest terms Combine the steps together to create an algorithm

Identify the name given to adding and testing small amounts of code. Dead code Temporary variables Refactoring Incremental development

Incremental development

Identify the contractual term given to a Python function's name, argument list, behavior, and any return value. Generalization Encapsulation Interface Branch

Interface

Identify the term given when an algorithm is applied to each element in a sequence. Filter Delimiter Reduction Map

Map

Identify the alternate term given to Python object functions used with the dot notation. Conditionals Booleans Methods Functions

Methods

Identify the name of the highlighted Python operator in the following code. print(10 % 2) Concatenation operator Modulus operator Remainder operator Division operator

Modulus operator

Computer program instructions fall into a number of basic instruction categories. Identify the invalid basic instruction category. Math Conditional execution Natural language Input

Natural language

Identify the problem in the following Python code. num = input("Enter your age: ") if num >= 21: print("21!") else: print("You'll be 21 in ", 21 - num, "years") Num is a float Num is a string Invalid relational operator Input does not accept arguments

Num is a string

Identify the reason why a for loop is appropriate for the repeat() function shown below rather than a while loop. def repeat(data, count, spacer = '_'): result = '' for i in range(count): result = result + data if i < count - 1: result = result + spacer return result Number of iterations is unknown Break statements are not allowed in functions While loop does not support concatenation Number of iterations is known

Number of iterations is known

Identify the term given to the act of refining and improving your code. Generalization Refactoring Encapsulation Composition

Refactoring

Identify the purpose of the following code. fin.seek(0) Reset file pointer to the start of the file Search file contents for an integer Reset file pointer to the end of the file Search file contents for a string

Reset file pointer to the start of the file

Program debugging is like an experimental science. Below are the steps to follow when debugging. Identify the correct order.

Run your code Identify a problem Isolate what you think is the cause of the problem Propose a solution to resolve the problem Test your hypothesis by modifying the code Run your code to test if your change resolved the problem

Identify the pattern that traverses a sequence and returns a result. Traversal pattern Guardian pattern Counter pattern Search pattern

Search pattern

Identify the type of error encountered when a program will not execute. Runtime error Syntax error Semantic error Expression error

Syntax error

Identify why the following code prints 'o' rather than 'C'. info = 'Coding is fun!' print(info[1]) The bracket operator uses 1-based indexing The bracket operator uses 0-based indexing

The bracket operator uses 0-based indexing

Identify the problem with the following code. def square(num): return num * num print('Sum:', num * num) The code contains dead code The print() function must use concatenation The function must be a Boolean function Void functions cannot contain output

The code contains dead code

Identify the problem with the following code. num = 3 result = 0 while num > 0: result = result + num The code results in an infinite loop The conditional must use >= rather than > The variable result must not be initialized to 0 The code must be part of a function

The code results in an infinite loop

Describe the output from the following code. info = 'Coding is fun!' index = len(info) * -1 result = '' while index < 0: result = info[index] + result index = index + 1 print(result) An empty string is printed The original string value is printed The reverse of the original string is printed The code will generate a syntax error and will not execute

The reverse of the original string is printed

Identify why the following code will never prompt the user for input. while False: line = input('> ') if line == 'done': break print(line) print('Done!') Input is invalid within a while loop The while loop will never execute The break statement is invalid within a while loop The break statement requires a function

The while loop will never execute

dentify the shape drawn by the following Python code. t.fd(100) # Assume t is a valid Turtle Object t(120) t.fd(100) t.lt(120) t.fd(100) Square Circle Line Triangle

Triangle

After executing a Python script file using IDLE, any functions defined within the script file will be available to call from the IDLE shell. True False

True

An algorithm consists of exact, repeatable steps to solve a problem. True False

True

Coding and executing Python expressions from a Python script file have no visible effect in the Python Shell. True False

True

Creating your own Python functions is creating your own personal API. True False

True

Identify the output of the following Python code. price = 10.0 discount = 0.2 print(price * discount > 8.0 or price >= 10) 8 10 True False

True

Lengthy conditional expressions may span multiple lines using parentheses. True False

True

List function parameters are aliases for the list argument from the calling code. True False

True

Testing a parameter data type using isinstance() is an example of the guardian pattern. True False

True

The Python isdigit() method returns True if all the characters are digits, otherwise False. True False

True

The following Python function illustrates one principle of functional programming. def delete_list_first_element(t): new_t = t[:] if len(new_t) > 0: del new_t[0] return new_t True False

True

The in operator can be used to search for one string within another string. True False

True

When creating Python functions, clear and explicit preconditions and postconditions ease the debugging process. True False

True

When writing software, you should always consider special use cases, such as empty or unexpected input. True False

True

Identify the correct description of composition. Debugging small amounts of code Using smaller functions to build larger functions Defensive programming Employing multiple return statements within a single function

Using smaller functions to build larger functions

Identify the correct order of the steps to effectively write Python code using the encapsulation and generalization development plan.

Write a small program without function Identify a block of code that stands alone and encapsulate it into a function Generalize the function by adding appropriate parameters Repeat until you have a set of working functions

Identify the correct value of the variable piece in the following Python code. letters = ["A", "B", "C"] letters.append("Z") piece = letters[1:2] ["A"] ["B", "C"] ["B"] ["A", "B"]

["B"]

Identify the value of the my_list variable after complete execution of the following code. s = "what time is it" my_list = s.split() for item in my_list: item += "Noon!" ["what", "time", "is", "it"] ["noon", "noon", "noon", "noon"] "what time is it" ["what time is it"]

["what", "time", "is", "it"]

Identify the single answer that is a VALID Python variable name. 1_qty import #qty _qty

_qty

Identify the Python statement to immediately exit a loop. break exit slice abs

break

Common Python variable name for a file input object. t fin input file

fin

Identify the type of function in the following code. def square(num): return num*num state stack void fruitful

fruitful

Identify the syntax to declare an empty list in Python. my_list = list("empty") my_list = [:] my_list = {} my_list = []

my_list = []

Identify which method does NOT modify the original list. remove() sort() pop() sorted()

sorted()

Identify the correct function to ensure the following code does not error. age = 25 print("My age is " + age) type() float() int() str()

str()

Identify the single answer that IS a Python statement. 97 math.pi n + 10 zip = '97403'

zip = '97403'


Set pelajaran terkait

ACCT 3731 - Advanced Accounting: Exam 4 (Final)

View Set

Chapter 11 Terms and Definitions

View Set

Business Statistics (True/ False)

View Set

2.2 Network Devices & Software Defined Networking

View Set

3.07 Identify and locate major countries, including: Brazil, China, Egypt, France, Great Britain, India, Italy, Japan, Russia, Spain

View Set

World History - 12.4-12.6 Review

View Set

AP World History Module 9 Vocabulary

View Set

Chapter 9 - The housing decision factors and finances

View Set

Chapter 4: The Components of the System Unit

View Set

Psy 456 Death and Loss exam #1 Study guide

View Set

Ethics exam 1, Ethics quiz questions exam 1, ethics Cahn book exam 1, ethics overheads and notes exam 1

View Set

Anatomy Questions - Hip, Thigh, Posterior Leg

View Set