PYTHON 2984

Ace your homework & exams now with Quizwiz!

The function add5() below returns the number 5 added to the argument. What value will the variable 'x' hold after the line is executed? x = add5(10) * add5(2)

105

After the third iteration of the loop, what is the value of sum? sum = 0 values = [4,2,6] for value in values: sum = sum + value

12

What will be the output of the following code snippet: class Sales: def __init__(self, id): self.id = id id = 100 val = Sales(123) print(val.id)

123

How many branches does this code have? if conditional: print(5) else: print(2)

2

How many branches does this code have? if conditional: print(5) print(2)

2

How many elements will the result of this list comprehension have? old = [1,2,3] new = [old*2 for i in old if i > 1]

2

What is the value stored in "my_var" after the following code is executed? my_var = [1,2,3][1]

2

How many branches does this code have? if conditional: if second_conditional: print(5) print(1) print(2)

3

How many elements will the result of this list comprehension have? old[1,2,3] new = [old*2 for i in old]

3

Predict the result of this expression: (10 + 8) % 12

6

Type the character used at the end of the first line of a for loop.

:

Package

A collection of modules that share a namespace

Which of the following statements is true?

A non-private method in a superclass can be overridden

Which statement best describes polymorphism?

A way to permit objects of different types and behaviors to be treated as the same general type

An accessor method is used to:

Access values internal to a class from outside

Object

An instance of a class

What is the output of the following code: class Dog: def walk(self) :return "*walking*" def speak(self): return "Woof!" class JackRussellTerrier(Dog): def speak(self): return "Arf!" bobo = JackRussellTerrier() bobo.speak()

Arf!

Class

Blueprint that defines an object

What type of thing is returned from the function below? def is_on_fire(): return True

Boolean

Data Science is a straightforward process with no iterative design.

False

Data Science is another name for Computer Science.

False

Every function must return an integer or a string.

False

Every if statement must be followed by either an else or an elif.

False

Markdown is a type of Python code.

False

Methods always change the internal state of a mutable object.

False

Notebooks are a basic part of a Python installation.

False

Notebooks are strictly a tool for educational purposes

False

Overriding means changing behavior of methods of derived class methods in the base class.

False

The print() function always returns a string.

False

The print() function is necessary to call a function.

False

The program below will NOT loop forever. count = -5 while count < 0: count = count - 1 print(count)

False

The return statement is used to send a variable out of a function.

False

The overarching goal of software testing is to:

Find whether the software works incorrectly

What is the subtype of the following literal value? [4.5, 3.2, 7.3]

Float

Library

Functional structure that is used for general-purpose access from other programs

Predict the result of this expression: "Hello world".upper()[0:5]

HELLO

In the following code, the print statement is ________ the ifstatement. if conditional: print("The conditional was true")

Inside

Is the print call before, inside, or after the for loop? for name in names: print(name)

Inside

What is the benefit of "duck typing?"

Less restriction on the type values that can be passed to a method

What is the type of the following list value? [4.5, 3.2, 7.3]

List

What is the type of the result of the following expression? "1,2,3,4".split(",")

List

How should software be tested?

Manually and Automation

Which loop pattern does this code most resemble? lowest = 100 grades = [90,64,72,50] for grade in grades: if lowest > grade: lowest = grade print(lowest)

Max/min

A mutator method is used to:

Modify values internal to a class from outside.

What is the value of number_of_users after this program executes? if False: number_of_users = 5 print(number_of_users)

No value, because an error occures since the value has not been defined

Faults found by users are due to:

Poor software and poor testing

KeyError

Python couldn't find a key in a dictionary

IndexError

Python couldn't find a valid location in a list

TypeError

Python tried to apply an operation/function to an inappropriate type

NameError

Python tried to use a variable/function that isn't defined

What is the type of the Iteration Variable in this code? groceries = ["Apples", "Cookies", "Steaks"] for grocery in groceries: print(grocery)

String

Mark each of the following statements about for loops that are true:

The iteration variable will take on each value of the list variable, one at a time. AND Like an if statement and a function call, the for loop might cause the execution to not follow the order of the code lines

What does the __dict__ instance variable provide?

The methods provided by the class

A UML Class Diagram contains the following:

The name of the class, Variables stored within the class, Functions that modify attributes of the class

Which is these is the biggest reason for incorporate polymorphism into a software system?

The program will have a more elegant design and will be easier to maintain and update

SyntaxError

The python interpreter wasn't able to understand a line of code

ValueError

The value passed to a function is of incorrect type

A Notebook is composed of Markdown, Code, and the results of running that Code.

True

A class in Python is defined with the keyword class.

True

A class in which one or more methods are only implemented to raise an exception is called an abstract class.

True

A state represents the current values of all instance data internal to the object.

True

Composition enables Python to create a complex type by combining types of other objects.

True

Data Science involves extracting meaning from data.

True

Encapsulation is a design principle of OOP stating that only the methods of a class should be able to change the values of the instance variables.

True

Information hiding is a convention for hiding changes internal to an object from the user.

True

Lists and strings are both sequences of data.

True

Methods are functions that are internal to a class.

True

The elif is equivalent to an else with an if statement nested inside it.

True

The input() function always returns a string.

True

The program below will NOT loop forever. count = 10 while count >= 0: count = count - 1 print(count)

True

The return statement is used to send a value out of a function.

True

Values enter functions as arguments when the function is called, and then the arguments' values are assigned to parameters when the function's body begins executing.

True

What is the value of "any" after the following code is executed: conditions = [False, False, True, False] any = False for condition in conditions: any = any or condition print(any)

True

What is the value stored in "my_var" after the following code is executed? my_var = 5 in [1,3,5]

True

UML is an abbreviation of:

Unified Modeling Language

Which instance variable can tell you the name of any superclass?

___bases__

The constructor is always called:

__init__()

Module

a file that contains 0-n classes

Software testing activities should start:

as soon as possible in the development life cycle

How would you define a function named openDoor? Assume it takes no arguments.

def openDoor():

A namespace prevents multiple instances of the same class from being created.

false

When creating a new object, the constructor is directly called by name.

false

All Python programs must have a main() function to control the execution of other functions.

False

All modules are packages, but not all packages are modules.

False

What is the output of the following code: class Dog: def walk(self) :return "*walking*" def speak(self): return "Woof!" class JackRussellTerrier(Dog): def speak(self): return "Arf!" bobo = JackRussellTerrier() bobo.walk()

*walking*

What is printed after the code below is executed? def change_value(a_variable): a_variable = 5 return a_variable a = 0 change_value(a) print(a)

0

UML diagrams include:

Class diagrams Sequence diagrams State diagrams Component diagrams Object diagrams Activity diagrams Timing diagrams Use case diagrams Package diagrams Deployment diagrams

The correct way to instantiate the following class is: class Dog: def __init__(self, name, age): self.name = name self.age = age

Dog("Rufus", 3)

Which of these statements are true?

Each object is an instance of a class, A method describes what an object can do, Everything in Python is an object, Assigning a value to a variable is the same operation as binding a name to an object, The self parameter is an object's way to refer to itself, A constructor is a method that creates an object.

Which of the below are magic ("dunder") methods that are defined for every Python object?

Everything but __self__()

"1" + "1" = "2"

False

A while loop will always execute at least once.

False

Given the following code snippet, which of the following pairs of statements and outputs are correct? class Dog: def __init__(self, name, age): self.name = name self.age = age class JackRussellTerrier(Dog): pass class Dachshund(Dog): pass class Bulldog(Dog): pass miles = JackRussellTerrier("Miles", 4) buddy = Dachshund("Buddy", 9) jack = Bulldog("Jack", 3) jim = BullDof("Jim", 5)

isinstance(jack, Dachshund) False, isinstance(miles, Bulldog) False, isinstance(buddy, Bulldog) True, isinstance(miles, Dog) True

How would you call a function named openDoor? Assume it takes no arguments.

openDoor()

Given this program: name = input("What is your name?")def fix_capitalization(name):return name.title().strip()def print_message(name):print("Hello", name, "how are you?" which of the following lines of code will have the data flow correctly through both functions in order to print the message with the fixed capitalization?

print_message(fix_capitalization(name)) and name = fix_capitalization(name)print_message(name)

Which of the following code snippets are equivalent?

squared = [] for value in values :squared.append(value**2) and squared = [value**2 for value in values]

The best definition of software testing is:

technical investigation done to expose quality-related information about the product under test

The program below will NOT loop forever. count = 0 while count > 0: count = count + 1 print(count)

true

When should you stop testing?

when the test completion criteria have been met

Which of the following statements is most accurate for the declaration x = Circle()?

x contains a reference to a Circle object


Related study sets

consumer behavior chapter 9 questions

View Set

Chemical Equilibria and Neutralization

View Set

Pathophysiology chapter 1-4,7 example questions

View Set

Unit 14 Determine the Value of a Collection of Coins and Bills

View Set