Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Student: def __init__(self, my_id): self.id = my_id Suppose student1 is a Student object. Which of the following statements displays the value of the instance

  1. class Student: def __init__(self, my_id): self.id = my_id

    Suppose student1 is a Student object. Which of the following statements displays the value of the instance variable id?

    A.

    print(student1.id)

    B.

    print(student1.self.id)

    C.

    Both A and B

    D.

    None of the above

3.33 points

QUESTION 21

  1. class Student: def __init__(self, my_id): self.__id = my_id def get_id(self): return self.__id Suppose student1 is a Student object. Which of the following statements displays the value of the instance variable id?

    A.

    print(student1.id)

    B.

    print(student1.get_id())

    C.

    Both A and B

    D.

    None of the above

3.33 points

QUESTION 22

  1. Which of the following statements make Class A the base class of class B?

    A.

    class A(B):

    B.

    class B(A):

    C.

    class A : B:

    D.

    class B : A:

3.33 points

QUESTION 23

  1.  
    import random for i in range(10): num = random.randint(10, 20) if num <= 15: continue print(num) 

    Which statements about the program above is true?

    A.

    The program always generates 10 random integers

    B.

    The program always displays 10 random integers

    C.

    Both (A) and (B) are true

    D.

    Both (A) and (B) are false

3.33 points

QUESTION 24

  1. x is a floating point number. Which of the following statements is true?

    A.

    math.ceil(x) is larger than or equal to x

    B.

    math.floor(x) is smaller than or equal to x

    C.

    Both (A) and (B) are true

    D.

    Both (A) and (B) are false

3.33 points

QUESTION 25

  1. while True: try: x = int(input("Enter an integer: " )) if x <= 100: raise() except: print() else: break 

    Which of the following statements is true?

    A.

    The program will stop if an integer smaller than or equal to 100 is entered.

    B.

    The program will never stop

    C.

    The program will stop if something that is not an integer is entered

    D.

    The program will stop if an integer larger than 100 is entered

3.33 points

QUESTION 26

  1. x is a datetime object. Which of the following statements subtracts 5 days from it?

    A.
    x.day = x.day - 5
    B.
    x = x - datetime(days=5)
    C.
    x = x - timedelta(days=5)
    D.
    x = x.day - 5

3.33 points

QUESTION 27

  1. # insert a statement here
    n = f(n)
     

    Which of the following statements should be inserted so that n will increase by 1?

    A.
    f = lambda x: x + 1
    B.
     
     
     
    f = lambda n + 1
    C.
     
     
    def f: n: n + 1
     
     
     
    D.
    f = n: n + 1

3.33 points

QUESTION 28

  1. Which of the following functions returns all integers between 0 and n-1 one number at a time?

    A.
    def my_function (n): for i in range(n): return i
    B.
     
     
     
    def my_function (n): for i in range(n): yield i
    C.
     
     
    def my_function (n): my_list = [] for i in range(n): my_list.append(i) return my_list
     
     
    D.
    def my_function (n): my_list = [] for i in range(n): my_list.append(i) yieid my_list

3.33 points

QUESTION 29

  1. course_list is a list of tuples. Each tuple has two elements. The first element is instructor. The second element is enrollment. Which of the following statements sorts course_list by instructor?

     
    A.
    course_list = sorted(course_list, key=1)
    B.
     
     
     
    course_list = sorted(course_list, key=0)
    C.
     
     
    course_list = sorted(course_list, key=lambda t:t[1])
     
     
    D.
    course_list = sorted(course_list, key=lambda t:t[0])

3.33 points

QUESTION 30

  1. x and y are two lists.

    z = zip(x, y)
     

    Which of the following code fragments swaps the elements of x and y, i.e. elements of list x move to list y, while elements of list y move to list x?

     
    A.
    y, x = zip(*z) x = list(x) y = list(y)
    B.
    x = list(y) y = list(x)
    C.
     
     
    x = y y = x
     
     
    D.
    z.unzip(x,y) x = list(x) y = list(y)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions