BEST代写-线上留学生作业代写 & 论文代写专家

成立于2015年的老牌留学生代写品牌-BEST代写提供超过百门冷热门留学学科的作业和论文代写服务。全网BEST原创,高质,准时的留学生代写。

计算机代考|COMP 202 Final examination

计算机代考|COMP 202 Final examination

这是一篇来自加拿大的关于COMP 202最终测验的计算机代考

 

Multiple choice questions, 3 points each (36 points)

  1. (3 points) What will this code output?

d = {‘first’: {‘name’: ‘Kate’, ‘id’: 260800000}}

x = d[‘first’]

for i in str(x[‘id’]):

d[i] = x

print(len(d))

  1. 10
  2. An exception will occur.
  3. 5
  4. 1
  5. (3 points) Which of the below statements regarding methods are correct? Select all that apply. You must

select all the correct answer(s) to get the points for this question.

A.An instance method must take at least one argument, called ‘cls’ by convention (though any name is OK).

B.You must put a decorator on the line above a method defifinition so that the Python interpreter what kind of method it is.

C.A class method can be called using dot notation on an instance of the class.

D.For a class that represents a bookstore, a method that prints out the list of books contained in the store

would make most sense as an instance method.

  1. (3 points) Assume that a Painting class has been defifined whose constructor takes two arguments. The class

Painting also contains an instance method is_fake which returns a boolean. Which of the following

methods, if added to the class, would let the code below execute without error? Select all that apply.

You must select all correct answers to get the points for this question.

orders = Painting(“Orders”, “Philip Guston”)

blue_sky = Painting(“Blue Sky”, “Philip Guston”)

print(orders > blue_sky)

  1. @staticmethod

def __gt__(painting1, painting2):

….return not painting1.is_fake() and painting2.is_fake()

  1. def __eq__(self, other):

….return other is not None and other.is_fake()

  1. def __gt__(self, painting2):

….return False

  1. def __gt__(self, other):

….return other.is_fake() and not self.is_fake()

  1. (3 points) What will this code output?

t = ((13, 37), (900, 1))

for i, k in enumerate(t):

print(dict([(i, k)]))

  1. {13: 37}

{900: 1}

  1. TypeError: tuples of tuples cannot be enumerated
  2. {0: (13, 37)}

{1: (900, 1)}

  1. TypeError: tuple cannot be unpacked
  2. {13: 37, 900: 1}
  1. (3 points) Consider the following error traceback obtained during execution of a piece of code.

Traceback (most recent call last):

File “alt_mt.py”, line 46, in <module>

main()

File “alt_mt.py”, line 42, in main

remove_snow_from_string(input(“Enter snowy string: “))

File “alt_mt.py”, line 18, in remove_snow_from_string

snow_helper(snow_s)

File “alt_mt.py”, line 5, in snow_helper

raise ValueError(“Rain in string!”)

ValueError: Rain in string!

In which function did the exception that caused this error fifirst occur?

  1. input
  2. There is not enough information in the traceback to know for sure.
  3. remove_snow_from_string
  4. main
  5. snow_helper
  1. (3 points) What will this code output?

import copy

class Author:

def __init__(self, name):

self.name = name

me = Author(“Disgruntled Bovine”)

you = Author(“Disgruntled Bovine”)

if me == you:

print(“Imposter!”)

other = copy.copy(me)

if other == me or other == you:

print(“I am Spartacus.”)

  1. Imposter!

I am Spartacus.

  1. An error traceback will be printed.
  2. I am Spartacus.
  3. Nothing will be printed.
  4. Imposter!
  1. (3 points) The following function f takes a monotone binary string as input. A monotone binary string

consists of only 0s, and 1s and with all the 1s coming after all the 0s : ‘000 . . . 0011 . . . 11′. Examples

of monotone binary strings are ‘00111’, ‘000001, 0111′ or ’01’. Assume the monotone binary

string has at least one 0 and at least one 1.

What does f return?

def f(data):

low = 0

high = len(data) – 1

while low <= high:

middle = (low + high) // 2

if data[middle] < data[middle + 1]:

return middle

elif data[low] == data[middle]:

low = middle + 1

else:

high = middle – 1

  1. The number of 1s in the string
  2. The index of the fifirst 1 in the string
  3. The number of 0s in the string
  4. The index of the last 0 in the string
  1. (3 points) What will this code output?

x = [1, 2, 3]

for i in range(len(x), 0, -1):

try:

print(1 / (x[i] – 2))

except ZeroDivisionError:

print(“Bad math”)

except:

print(“Something went wrong”)

finally:

print(“PRINT ME!!”)

  1. Something went wrong

PRINT ME!!

1.0

PRINT ME!!

Bad math

PRINT ME!!

  1. Something went wrong

PRINT ME!!

  1. Something went wrong

Bad math

1.0

-1.0

PRINT ME!!

  1. Something went wrong

1.0

Bad math

PRINT ME!!

  1. 1.0

PRINT ME!!

Bad math

PRINT ME!!

-1.0

PRINT ME!!

bestdaixie

评论已关闭。