Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1- Which list will be referenced by the variable number after the execution of t

ID: 3570861 • Letter: 1

Question

1- Which list will be referenced by the variable number after the execution of the following code?
   number = range(0, 9, 2)
a.   [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
b.   [1, 3, 5, 7, 9]
c.   [2, 4, 6, 8]
d.   [0, 2, 4, 6, 8]


2- What would you use if an element in a list is to be removed from a specific index?
a.   del statement
b.   remove method
c.   index method
d.   slice method

3- What method can be used to place an item in the list at a specific index?
a.   append  
b.   index  
c.   insert  
d.   Add  

4- What would be the value of the variable list after the execution of the following code?
list = [1, 2]
list = list * 3
a.   [1, 2] * 3  
b.   [3, 6]  
c.   [1, 2, 1, 2, 1, 2]  
d.   [[1, 2], [1, 2], [1, 2]]  

5- What would be the value of the variable list2 after the execution of the following code?
list1 = [1, 2, 3]
list2 = list1
list1 = [4, 5, 6]
a.   [1, 2, 3]  
b.   [4, 5, 6]  
c.   [1, 2, 3, 4, 5, 6]  
d.   invalid code  

6- What would be the value of the variable list2 after the execution of the following code?
list1 = [1, 2, 3]
list2 = []
for element in list1
   list2.append(element)
list1 = [4, 5, 6]
a.   [1, 2, 3]  
b.   [4, 5, 6]  
c.   [1, 2, 3, 4, 5, 6]  
d.   invalid code  

7- The primary difference between a tuple and list is that _____.
a.   when creating a tuple you don't use commas to separate elements  
b.   a tuple can only include string elements  
c.   a tuple cannot include lists as elements  
d.   once a tuple is created, it cannot be changed  

8- What will be assigned to s_string after the execution of the following code?
               special = '1357 Country Ln.'
               s_string = special[ :4]
a.   '7'
b.   '1357'
c.   '1357 '
d.   Invalid code

9- What will be assigned to the string variable even after the execution of the following code?
               special = '0123456789'
               even = special[0:10:2]
a.   '13579'
b.   '2468'
c.   '02468'
d.   Invalid code

10- What will be assigned to s_string after the execution of the following code?
               special = '1357 Country Ln.'
               s_string = special[-3: ]
a.   '531'
b.   'Ln.'
c.   ' Ln.'
d.   '7531'

11- What will be assigned to the string variable pattern after the execution of the following code?
                   i = 3
                   pattern = 'z' * (5*i)
a.   'zzzzzzzzzzzzzzz'
b.   'zzzzz'
c.   Error: '*' operator used incorrectly
d.   The right side of the '*' must be an integer.

12- When a method is called, what does Python make to reference the specific object on which the method is supposed to operate?
a.   state variable
b.   self parameter
c.   object data
d.   init procedure

13- What is the combining of data and code in a single object known as?
a.   Modularity
b.   Instantiation
c.   Encapsulation
d.   Objectification

14- What is another name for the mutator methods?
a.   Setters  
b.   Getters  
c.   Instances  
d.   Attributes  

15- _____ allows a new class to inherit the members of the class it extends.
a.   Encapsulation
b.   Domain
c.   Methods
d.   Inheritance

16- What gives a program the ability to call the correct method depending on the type of object that is used to call it?
a.   Polymorphism  
b.   Inheritance  
c.   Encapsulation  
d.   Methods  

17- In the following line of code, what is the name of the subclass?
                   class Rose(Flower):
a.   Rose
b.   Flower
c.   Either
d.   Incorrect code

18- Of the two classes Cola and Soda, which would most likely be the subclass?
a.   Cola
b.   Soda
c.   Both
d.   Either

19- Which of the following is the correct syntax for defining a class dining which inherits from class furniture?
a.   class furniture(dining)
b.   class dining(furniture)
c.   class furniture(dining):
d.   class dining(furniture):


20- Which method will return an empty string when it has attempted to read beyond the end of a file?
a.   read  
b.   getline  
c.   input  
d.   readline  

Explanation / Answer

1) d

since starts from 0 and end with 9 with 2 numbers interval

2)d slice(index,1)...here 1 represents remove 1 item only

3) b index...if you want to put at partucular position

4)b

5)a...just copyinh list 1...here we are not using opointers so it wont change after copying

6) a

7) d

8)b

9)c

10)c

11)a

12)b

13)c

14)c

15)d

16)b

17)b

18)a

19)c

20)d