IT209 Quiz 1 - 3

Ace your homework & exams now with Quizwiz!

What is the right way to access a class variable "wheels" for a class named 'Car'?

Car.wheels

What is the outcome of the following code? class Vowel(str): def all_vowel(self): vowels = ['a', 'e', 'i', 'o', 'u'] for char in self: if char not in vowels: return False return True s1 = Vowel('able') print(s1.all_vowel()) #outcome from this line

False

Write exact outcome of the following code? class Point(object): def __init__(self, x, y): self.x = x self.y = y def equal(self, other): if self.x == other.x and self.y == other.y: return True else: return False p1 = Point(4,2) p2 = Point(4,10) print(p1.equal(p2)) #outcome of this line

False

super() function call can only be made in the __init__ method

False

Below is a definition of inheritance. What will be the outcome of the following code? class Tree(object): def flower(self): raise NotImplementedError('Subclass needs to implement') class Fern(Tree): def flower(self): print('Ferns do not have flowers') #object creation f = Fern() f.flower() #outcome of this line

Ferns do not have flowers

What would be the data type of info of the following code? f = open('input.txt', 'r') info = f.readlines() f.close()

list

Any variable defined inside a function is considered to be in ______ scope?

local

'self' is associated with which of the following concept ? (Choose the most correct one)

object

By default, _____ class is the parent of all classes we define in Python.

object

__init__ method is invoked when a ______ is generated. (Choose the most correct one)

object

What does the dictionary method values() return?

only values

Which of the following syntax is right way to access instance variable first_name of a Person class object p?

p.first_name

You are given the following __init__ method for class 'RadioStation'. Which of the following will create a Radio object with station number 92.8 and station name "mason radio"? def __init__(self, name, number): self.name = name self.number = number

r = RadioStation ("mason radio", 92.8)

What would be the content of s2 after slicing operation? s1 = "ABC_D_EF" s2 = s1[2:5]

'C_D'

What will be the outcome of the following code? class Cat(object): def sound(self): print ("Meoww") class Dog(object): def sound(self): print ("Woof woof!") def makeSound(animalType): animalType.sound() c = Cat() #Cat object d = Dog(). #Dog object makeSound(c) makeSound(d)

'Meoww' then 'Woof woof!'

Which of the following statement is true?

* OOP models real life problems * OOP is a way to create custom data type in Python * Class bundles together similar object

Which is the correct operator to increment the value of a varibale by 1?

+=

What will the following code print? def sq(x, y=0): return x*y calc = sq(4) print(calc)

0

What would be the output of the following code? for i in range(5): print (i, end = ',')

0,1,2,3,4.,

Write exact outcome of the following code as generated by last print statement. class Employee(object): total = 0 def __init__(self, name, address): self.name = name self.address = address Employee.total += 1 e1 = Employee('Jane Doe', '4400 Univ Dr.') e2 = Employee('Mary Mont', '7800 Fairy Tree') print(Employee.total) #outcome of this line

2

Write exact syntax to append an Item object in the cart list class Item(object): cart = [] #class variable def __init__(self, name, price): self.name = name self.price = price #correct syntax to append an Item object to cart item1 = Item('bread', 2.48)

Item.cart.append(self)

What would be the output of: range(10, 15, -1)?

No outcome

what will the following code print? def fun(x, y): #definition d = {} d[x] = y r = fun(4, 5) #call print(r)

Nothing will be printed

Which of the following is not true about inheritance?

Parent class can access all the attributes in child class

Below is a definition of a polymorphic function and a class. What will be the outcome of the following code? class Audio(object): def audio_sound(self): print('Boo Boo!') def makeSound(animalType): animalType.sound() #function call a = Audio() makeSound(a) #outcome of this line

Raise an error

Which of the following is false about abstract base class (ABC)?

Subclasses do need to complete the definition of abstract methods

'self' refers to current object.

True

'super()' function refers to parent class.

True

Class is a way to define custom data type in python.

True

Method overriding is altering or replacing a method of the superclass with a new method (with the same name) in the subclass.

True

What would be the value of the following expression: True and False or True?

True

__str__ method returns string

True

What would be the content of list2 at the end? list1 = [10, 20] list2 = [2, 3] list2.extend(list1)

[2, 3, 10, 20]

Define a class Ant which is a subclass of Insect. Just provide the definition line.

class Ant(Insect)

Which of the following is a valid definition of 'Building' class with one instance variable 'address'?

class Building(object): def __init__(address): self.address = adresss

Define a class CartList which is a subclass of list class.

class CartList(list)

What is the correct definition of a class ComboDevice, that has two parents Scanner and Copier?

class ComboDevice(Scanner, Copier):

Which of the following is a valid definition of 'Network' class?

class Network(object)

Define a class Parent which is a subclass of Granddad and Grandmom. Just provide the definition line.

class Parent( Granddad, Grandmom )

Which of the following is a valid definition of 'RadioStation' class?

class RadioStation(object)

Which of the following is a valid definition of 'Superman' class - a subclass of Superhero?

class Superman(Superhero):

What is the correct way to add an item ('VA', 'Virginia') to a dictionary d where key = 'VA' and value = 'Virginia'?

d['VA'] = 'Virginia'

The correct way to remove an item from dictionary d is:

del d['VA']


Related study sets

Reference Angles, Coterminal angles, Standard Position, Coterminal and Reference Angles

View Set

Module 9: Monitoring for Health Problems

View Set

Bsn 395 compass Hesi mid study plan A————NU373 Week 3 EAQ Evolve Elsevier: Oxygenation (Asthma, COPD, RSV)

View Set

Honors persuassion exam 1 psy 4390

View Set

Their eyes were watching God 8-12 quiz

View Set