quiz 5.1

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What will be the output? class num: def __init__(self,a): self.number = a def __mul__(self, b): return self.number + b.number numA = num(5) numB = num(10) product = numA * numB print(product)

15

Choose the correct term to complete the sentence. __________________ uses objects that represent classes to manage, manipulate, and store data.

Object-oriented programming

In a single file, you wrote a bike class and used this line of code in the program. bikeA = bike('Acme',111) Which statement is true about the code in your file?

The code to define your class (beginning with "class bike") must come before the line "bikeA = bike('Acme',111)."

Which statements are true? Select 4 options.

Variables defined in the constructor of a class can be accessed by the main program that uses instances of the class. A class variable can be a different type of class. A class variable can be a list of instances of a different class. Functions defined in a class are called methods.

What character, when used at the beginning of the constructor name in a class, makes the class variables have a scope limited to the function?

_ (an underscore)

What will be the output of the following program? def average(a, b): total = a + b return total / 2 ave = average(7,11) print("Total", total) print ("Average", ave)

an error statement since total's scope is limited to the average function.

Choose the terms to complete the class definition. __________ bike: def __init__( _________, size, idNum, color ): self.size = size self.location = 10 self.color = color self.idNum = idNum

class self

Choose the missing parts of the program to have the following output. ________ pet: def __init__( ________ ,strSpecies,strName): self.species = strSpecies self.petName = strName def __str__(self): return self.species + " named " + self.petName # main program myPetA = pet('dog', 'Spot') myPetB = pet('cat', 'Fluffy') __________

class self print(myPetA)

Choose the missing line of code. class num: def __init__(self,a): self.number = a ____________: return self.number + b.number numA = num(5) numB = num(10) product = numA * numB print(product)

def __mul__(self, b)

Choose the correct line of code To overload exponentiation, use:

def __pow__(self, b):

_________ a variable in a program that represents a class and is created by an assignment statement

instance

What is the scope of each variable? class pet: def __init__(self,strSpecies,strName): self.species = strSpecies self.petName = strName def __str__(self): return self.species + " named " + self.petName class petCarrier: size = 'medium' color = 'red' The scope of petName is __________. The scope of color is __________.

local to the class pet accessible by all parts of the program

The function changeLocation is also called a _____. class bike: def __init__(self,size,idNum,color ): self.size = size self.location = 10 self.color = color self.idNum = idNum def changeLocation(self,newLocation): self.location = newLocation

method

__________ a function created within a class definition

method

Which line of code will create an instance of the pet class? class pet: def __init__(self,strSpecies,strName): self.species = strSpecies self.petName = strName

myPetA = pet('dog', 'Spot')

Choose the line of code that completes this program. Output: dog named Tiger class pet: def __init__(self,strSpecies,strName): self.species = strSpecies self.petName = strName def __str__(self): return self.species + " named " + self.petName def changeName(self, newName): self.petName = newName # main program myPetA = pet('dog', 'Spot') ______________ print(myPetA)

myPetA.changeName('Tiger')

Which line of code will move the raft to the Skykomish River? class raft: def __init__(self,capacity): self.capacity = capacity self.location = 'Gauley' self.repairs = [] def moveRaft(self, newLocation): self.location = newLocation myRaft = raft(30)

myRaft.moveRaft('Skykomish')​

_____ is the notion of repurposing a common operation.

polymorphism

What is the missing term? class raft: def __init__( ________ ,capacity): self.capacity = capacity self.location = 'Gauley' self.repairs = []

self


Kaugnay na mga set ng pag-aaral

Taxes, Retirement, and Other Insurance Concepts 10/9/2019

View Set

Pediatric Growth and Development Quiz 3

View Set

Clinical Chemistry Rotation Exam 2 Medical Laboratory Science Review (5.2)

View Set

Chapter 5 Practice Quiz- Part one (Principles of Marketing)

View Set

Bio 1 - Exam 3: Mastering Bio Questions

View Set

Chapter 9: Communication and the Therapeutic Relationship

View Set