Intro to programming final study guide

Ace your homework & exams now with Quizwiz!

What is output? class PairDivision: def __init__(self, a = 1, b = 1): self.a = a self.b = b def __floordiv__(self, other): a = self.a // self.b b = other.a // other.b return(a, b) p1 = PairDivision(10.3, 2.5) p2 = PairDivision(20.5) print(p1 // p2) a. (4.0, 20.0) b. (1.0, 2.0) c. (0.4, 2.0) d. (0.5, 2.5)

a. (4.0, 20.0)

What is the value of x after the following code is executed? x = 17 if x * 2 <= 34: x = 0 else: x = x + 1 x = x + 1 a. 1 b. 18 c. 19 d. 35

a. 1

Which function call would cause an error? def print_product(product_name, product_id, cost): print(f'{product_name} (id: #{product_id}) - ${cost:.2f}') a. print_product('Speakers', 21224, 32.99) b. print_product('Speakers', 32.99, 21224) c. print_product('Speakers', cost=32.99, product_id=21224) d. print_product(product_id=21224, product_name='Speakers', cost=32.99)

b. print_product('Speakers', 32.99, 21224)

Which expression for YYY will result in an output of "Pass" only if x is exactly 32? if YYY: print('Pass') else: print('Fail') a. x != 32 b. x == 32 c. x >= 32 d. x <= 32

b. x == 32

What is the value of rgb_a? colors = {1: 'red', 2: 'green', 3: 'blue', 4: 'yellow'} popped_item = colors.pop(4) colors.update({ 4: 'alpha'}) rgb_a = {} rgb_a['items'] = colors a. { 'items': { 1: 'red', 2: 'green', 3: 'blue', 4: 'yellow'}} b. { 'items': { 1: 'red', 2: 'green', 3: 'blue', 4: 'alpha'}} c. { 'items': 'colors'} d. { 1: 'red', 2: 'green', 3: 'blue', 4: 'alpha'}

b. { 'items': { 1: 'red', 2: 'green', 3: 'blue', 4: 'alpha'}}

What is output? dict1 = {1: 'Hi', 2: 'Bye'} dict2 = {2: 'Yes'} dict1.update(dict2) dict3 = {3: 'No'} dict1.update(dict3) print(dict1) a. {1: 'Hi', 2: 'Bye', 2: 'Yes', 3: 'No'} b. {1: 'Hi', 2: 'Yes', 3: 'No'} c. {1: 'Hi', 2: 'ByeYes', 3: 'No'} d. {1: 'Hi', 2: 'Yes', 2: 'Bye', 3: 'No'}

b. {1: 'Hi', 2: 'Yes', 3: 'No'}

What is output? my_dict = {x: x*x for x in range(0, 6)} second_dict = {} #new dictionary for keys, values in my_dict.items(): if values <= 16: second_dict[keys] = values #Adding second_dict as an element of my_dict my_dict['second_dict'] = second_dict for key, value in my_dict['second_dict'].items(): print(f'{my_dict["second_dict"][key]}:{key}', end=' ') a. 0:0 1:1 2:2 3:3 4:4 b. 4:16 3:9 2:4 1:1 0:0 c. 0:0 1:1 4:2 9:3 16:4 d. 16:4 9:3 4:2 1:1 0:0

c. 0:0 1:1 4:2 9:3 16:4

What is the output? num = 10; while num <= 15: print(num, end=' ') if num == 12: break num += 1 a. 10 b. 10 11 c. 10 11 12 d. 10 11 12 13 14 15

c. 10 11 12

What is the output? def find_sqr(a): t = a * a return t square = find_sqr(10) print(square) a. 0 b. 10 c. 100 d. (Nothing is outputted)

c. 100

What is the length of the dictionary my_dict = {'Country':'India','State': {'City':'Delhi', 'Temperature':40}}? a. 4 b. 3 c. 2 d. 5

c. 2

What is the final value of z? grades = { 'A': 90, 'B': 80, 'C': 70, 'D': 60 } my_grade = 70 if my_grade not in grades: z = 1 else: z = 2 if 'F' in grades: z = z + 10 else: z = z + 20 a. 11 b. 12 c. 21 d. 22

c. 21

What is the ending value of count? my_list = [3, -4, 0, -1, 2, 1, 8] n = 0 count = 0 While n < length of my_list If my_list[n] > 0 count = count + 1n = n + 1 a. 1 b. 3 c. 4 d. 5

c. 4

What is the output? def display(product, options=[]): if 'monitor' in product: options.append('HDMI') print(product, options) display('Acer monitor') display('Samsung monitor') a. Acer monitor Samsung monitor b. Acer monitor ['HDMI'] Samsung monitor ['HDMI'] c. Acer monitor ['HDMI'] Samsung monitor ['HDMI', 'HDMI'] d. No output: using a list as a default argument is an error

c. Acer monitor ['HDMI'] Samsung monitor ['HDMI', 'HDMI']

When was Jen unemployed? if (year >= 2010 and year <= 2014): print('Jen employed at Regal Cinemas') elif (year >= 2018): print('Jen employed at AMC Cinemas') else: print('Unemployed') a. Before 2010 and from 2014 to 2018 b. 2014 to 2018 c. Before 2010 and from 2015 to 2017 d. 2015 to 2017

c. Before 2010 and from 2015 to 2017

What is the output? def modify(names, score): names.append('Robert') score = score + 20 players = ['James', 'Tanya', 'Roxanne'] score = 150 modify(players, score) print(players, score) a. ['James', 'Tanya', 'Roxanne'] 150 b. ['James', 'Tanya', 'Roxanne'] 170 c. ['James', 'Tanya', 'Roxanne', 'Robert'] 150 d. ['James', 'Tanya', 'Roxanne', 'Robert'] 170

c. ['James', 'Tanya', 'Roxanne', 'Robert'] 150

What is output? my_list = [['cat in a hat'], ['Dr', 'Seuss']] print(my_list[1][1:]) a. ['Dr'] b. ['in a hat'] c. ['Seuss'] d. ['Dr', 'Seuss']

c. ['Seuss']

What is output? my_list = [['a b c'], ['d e f']] new_list = my_list[0][0].split(' ') print(new_list[-2]) a. e b. a c. b d. d

c. b

Which of the following code blocks will print both keys and values? a. dict1 = {} dict1['number'] = 10 dict1['color'] = 'Red' dict1['word'] = 'Chair' for values in dict1: print(values) b. dict1 = {'number': 10, 'color': 'Red', 'word': 'Chair'} for keys, values in dict1.items(): print(dict1[keys], values) c. dict1 = dict(number = 10, color = 'Red', word = 'Chair') for keys, values in dict1.items(): print(keys, values) d. dict1 = {'number': 10, 'color': 'Red', 'word': 'Chair'} for keys, values in dict1: print(keys, dict1[keys])

c. dict1 = dict(number = 10, color = 'Red', word = 'Chair') for keys, values in dict1.items(): print(keys, values)

Choose the option in which the value of new_list is ['greetings']. a. my_list = ['hello', 'greetings', 'hi', 'hey']new_list = [i for i in my_list if len(i)<5] b. my_list = ['hello', 'greetings', 'hi', 'hey']new_list = [i for i in my_list if len(my_list)>5] c. my_list = ['hello', 'greetings', 'hi', 'hey']new_list = [i for i in my_list if len(i)>5] d. my_list = ['hello', 'greetings', 'hi', 'hey']new_list = [i for i in my_list if len(my_list[i])<5]

c. my_list = ['hello', 'greetings', 'hi', 'hey']new_list = [i for i in my_list if len(i)>5]

Which uses the concat() function to output: red fish blue fish? def concat(*args): s = ' ' for item in args: s += ' ' + item return s a. print(concat(['red, blue'], 'fish')) b. print(concat(red), concat(fish), concat(blue), concat(fish)) c. print(concat('red', 'fish', 'blue', 'fish')) d. print(concat(red, fish, blue, fish))

c. print(concat('red', 'fish', 'blue', 'fish'))

For num_diff = Diff(5, 25), complete the code to print the following outputwhen num_diff is printed. First Number: 5 Second Number: 25 Difference: -20 class Diff: def __init__(self, num1, num2): self.num1 = num1 self.num2 = num2 def __str__(self): XXX a. return('f{self.num1 - self.num2}') b. return(f'First Number: {self.num1} Second Number: {self.num2}',(self.num1 - self.num2)) c. return(f'First Number: {self.num1} Second Number: {self.num2}Difference: {self.num1 - self.num2}') d. return(f'First Number: {self.num1} \nSecond Number: {self.num2}\nDifference: {self.num1 - self.num2}')

c. return(f'First Number: {self.num1} Second Number: {self.num2}Difference: {self.num1 - self.num2}')

Which statement is equivalent to the following? if x == 1: t = 'minute' else: t = 'minutes' a. t = 'minutes' if x == 1 else 'minute' b. t = 'minute' if x != 1 else 'minutes' c. t = 'minute' if x == 1 else 'minutes' d. t = 'minute' + ('s' if x == 1 else '')

c. t = 'minute' if x == 1 else 'minutes'

Which of the following is an attribute of the class shown below? class Student: def __init__(self): self.age = 0 self.height = 0 self.weight = 0 a. student b. init c. weight d. def __init__(self)

c. weight

What is output? objects = {} objects['a'] = 'Chair' objects['b'] = 'Table' objects['c'] = 'Sofa' objects.clear() print(objects) a. {'a':'Chair', 'b':'Table', 'c':'Sofa'} b. {'Chair', 'Table', 'Sofa'} c. {} d. {'a', 'b', 'c'}

c. {}

What is a valid output? dict1 = {} dict1['Kilometer'] = 'Meter' dict1['Litre'] = 'Millilitre' dict1['Kilojoule'] = 'Joule' dict1['Ton'] = 'Kilograms' dict3 = {} for keys, values in dict1.items(): dict3[keys] = values val = dict3.pop('Ton') for keys, values in dict3.items(): print(f'1 {keys} = 1000 {values}', end=' ') print('or', end=' ') print(f'1 {keys} is equal to 1000 {dict3[keys]}')

a. 1 Kilometer = 1000 Meter or 1 Kilometer is equal to 1000 Meter 1 Litre = 1000 Millilitre or 1 Litre is equal to 1000 Millilitre 1 Kilojoule = 1000 Joule or 1 Kilojoule is equal to 1000 Joule

What is output? class Student: def __init__(self): self.age = 0 self.height = 0 self.weight = 0 student1 = Student() student1.age = 10 student2 = Student() student2.height = 155 print(student1.age, student1.weight, student1.height) print(student2.age, student2.weight, student2.height) a. 10 0 0 0 0 155 b. 155 0 0 0 0 10 c. 10 10 10 155 155 155 d. 10 0 155 10 0 155

a. 10 0 0 0 0 155

What is output? class Factorial: def __init__(self, num1 = 5): self.num1= num1 def calculate_fact(self): fact = 1 for i in range(1, self.num1 + 1): fact *= i print(fact) fact1 = Factorial(2) fact1.calculate_fact() a. 2 b. 5 c. 120 d. 1

a. 2

How many times will the body of the loop execute? my_list = [6, 2, 8, -1, 12, 15, -7] x = Get first my_list value While x is not negative put "Positive number!" to output x = Get next my_list value Put "Done" to output a. 3 b. 4 c. 5 d. 7

a. 3

Write the output for the following code. class Company(): def __init__(self,employees): self._employees = employees def __len__(self): return len(self._employees) members = Company(['manager','team lead','mentor']) print(len(members)) a. 3 b. ['manager','team lead','mentor'] c. employees d. TypeError: object of type 'Company' has no len()

a. 3

How many times will the print statement execute? for i in range(1, 3): for j in range(8, 12, 2): print(f'{i}. {j}') a. 4 b. 6 c. 9 d. 36

a. 4

What is the output? def print_app(app_id, plan='basic', term=30): print(f'App:{app_id} ({plan} plan, {term} days)') print_app(10032, term=14) a. App:10032 (basic plan, 14 days) b. App:10032 (basic plan, 30 days) c. App:10032 (plan, 14 days) d. No output: the function call produces an error

a. App:10032 (basic plan, 14 days)

What is output? new_string = 'Python' print(new_string[0:-1:2]) a. Pto b. Pytho c. on d. yhn

a. Pto

What is output? my_poem = 'Roses are red; Violets are blue' new_separator = '. 'new_poem = my_poem.split(';') print(new_separator.join(new_poem)) a. Roses are red. Violets are blue b. Roses.are.red.Violets.are.blue c. Roses;are;red;Violets;are;blue d. Roses are red Violets are blue

a. Roses are red. Violets are blue

What is output? my_string = 'The area postal code is 99501' print(my_string[-5:].isdigit()) print(my_string[:3].isupper()) print(my_string[:3].islower()) a. True False False b. False False False c. True True True d. False True True

a. True False False

what is the output? names = ['Bob, 'Jill', 'Xu'] ages = [24, 18, 33] for index in [2, 0, 1]: print (f'(names[index]} : {ages[index]}') a. Xu:33 Bob:24 Jill:18 b. Bob:24 Jill:18 Xu:33 c. Xu, Bob, Jill:33, 24, 18 d. Xu:24 Bob:18 Jill:33

a. Xu:33 Bob:24 Jill:18

What is the value of new_list? my_list = [['hey', 'hello', 'hi'], 'good morning'] new_list = [i + '!' for i in my_list[0]] a. ['hey!', 'hello!', 'hi!'] b. [['hey!', 'hello!', 'hi!'], 'good morning'] c. ['hey!', 'hello!', 'hi!', 'good morning'] d. [['hey!', 'hello!', 'hi!', 'good morning']]

a. ['hey!', 'hello!', 'hi!']

What is the value stored in new_list? my_list = [[10, 10], [100, 100], [500, 500, 1000]] for val in my_list: new_list = [i for i in val if i>10] a. [500, 500, 1000] b. [[500, 500, 1000]] c. [[100, 100], [500, 500, 1000]] d. [100, 100, 500, 500, 1000]

a. [500, 500, 1000]

What conditions have to be true to make the following code display "B"? if color == 'red': if style < 3: print('A') elif style < 5: print('B') else: print('C') elif color == 'blue': print('D') a. color is 'red' and style is 4 b. color is 'red' and style is 5 c. color is 'red' and style is 6 d. color is 'blue' and style is 3

a. color is 'red' and style is 4

Which XXX will display one more than half of the smallest value of w1, w2, and w3? def find_min_value(a, b, c): if a <= b and a <= c: return a elif b <= a and b <=c: return b else: return c w1 = 7 w2 = 3 w3 = 12 y = XXX print(y) a. find_min_value(w1, w2, w3)/2 + 1 b. find_min_value(w1+1, w2+1, w3+3)/2 c. find_min_value()/2 + 1, w1, w2, w3 d. find_min_value: w1, w2, w3() /2 + 1

a. find_min_value(w1, w2, w3)/2 + 1

Consider students = {'Semester_1' : {'Ryan':20, 'Mercy':25},'Semester_2' : {'Justin':21, 'Andrea':26}}. What command should be used to obtain the count of entries? a. len(students) b. students.size() c. students.len() d. size(students)

a. len(students)

What condition should replace ZZZ to output "Same name" only if the values of two variables are the same? my_name = input("Enter my name: ") your_name = input("Enter your name: ") if ZZZ: print("Same name") a. my_name == your_name b. my_name = your_name c. my_name is your_name d. id(my_name) == id(your_name)

a. my_name == your_name

Which choice fills in the blank so that the output prints one line for each item insports_list, as in: 1. Hockey? sports_list = [ 'Hockey', 'Football', 'Cricket' ] for i in _____: print(f'{i+1}. {sports_list[i]}') a. range(len(sports_list)) b. range(len(sports_list-1) c. range(1, len(sports_list)) d. range(1, len(sports_list)-1)

a. range(len(sports_list))

What is a possible output? rentals = { 'skis' : 20.00, 'boots' : 10.00, 'skates' : 4.00 } for x in rentals: print(x, end=' ') a. skis boots skates b. 20.00 10.00 4.00 c. skis: 20.00 boots: 10.00 skates: 4.00 d. x x x

a. skis boots skates

Complete the code to generate 'Rita Williams attends English class' as the output. class Student: def __init__(self,first_name, last_name, sub='Math'): self.sub = sub self.first_name = first_name self.last_name = last_name XXX a. student1 = Student('Rita', 'Williams', 'English') print(f'{student1.first_name} {student1.last_name} attends{student1.sub} class') b. student1 = Student('Rita', 'Williams') print(f'{student1.first_name} {student1.last_name} attends{student1.sub} class') c. student1 = Student() print(f'{student1.first_name} {student1.last_name} attends{student1.sub} class') d. Student('Rita', 'Williams', 'English') print(f'{Student.first_name} {Student.last_name} attends{Student.sub} class')

a. student1 = Student('Rita', 'Williams', 'English') print(f'{student1.first_name} {student1.last_name} attends{student1.sub} class')

What is output? items = {1: {'name': 'Chair', 'type': 'Plastic', 'size':'Small'}, 2: {'name': 'Sofa', 'type': 'wooden', 'size': 'Large'}} items[3] = {} items[3]['name'] = 'Table' items[3]['type'] = 'Wooden' items[3]['size'] = 'Middle' print(items[3]) a. {'name': 'Table', 'type': 'Wooden', 'size': 'Middle'} b. {'name': 'Chair', 'type': 'Plastic', 'size': 'Small'} c. {'name': 'Sofa', 'type': 'Wooden', 'size': 'Large'} d. {'name': 'Table', 'type': 'Plastic', 'size': 'Small'}

a. {'name': 'Table', 'type': 'Wooden', 'size': 'Middle'}

For print(f'{"Mike":XXX}{1:YYY}'), which XXX and YYY will generate'Mike=1' as the value of format_print? a. *>4, =>3 b. *>4, =>2 c. *>4, <2 d. *<5, =<2

b. *>4, =>2

What is the value of test_val after the following code is executed? a = 12 test_val = 6 if a * 2 == test_val: a = a + 7 else: test_val = 2 * a test_val = a + 1 a. 7 b. 13 c. 24 d. 25

b. 13

What is x's final value? x = 10 y = 20 if y <= 2 * x: x = x + 5 else: x = x * 2 a. 10 b. 15 c. 20 d. 25

b. 15

Identify all the keys (including nested dictionaries) in students = {'Semester_1': {'Aston':20, 'Julia':25}, 'Semester_2' : {'Ben':21,'Lisa':26}}. a. Aston, Julia, Ben, and Lisa b. Semester_1, Semester_2, Aston, Julia, Ben, and Lisa c. 20, 25, 21, and 26 d. Semester_1 and Semester_2

b. Semester_1, Semester_2, Aston, Julia, Ben, and Lisa

For the following constructor, identify the correct instantiation. class Student: def __init__(self,first_name, last_name, sub='Math'): self.sub= sub self.first_name = first_name self.last_name = last_name a. Student() b. Student('Daniel', 'Smith') c. Student('Daniel') d. Student(sub = 'English')

b. Student('Daniel', 'Smith')

Which expressions for YYY and ZZZ will output "Young" when user_age is less than 20 and "Young but not too young" when user_age is between 10 and 20? age_type = ' ' if YYY: age_type = age_type + "Young" if ZZZ: age_type = age_type + " but not too young" print(age_type) a. YYY: user_age < 20 ZZZ: user_age < 10 b. YYY: user_age < 20 ZZZ: user_age > 10 c. YYY: user_age > 20 ZZZ: user_age < 10 d. YYY: user_age > 20 ZZZ: user_age > 10

b. YYY: user_age < 20 ZZZ: user_age > 10

What is the output? def reset(data): data[1] = 34 print(data) data = [15, 0, 47, 12, 0] reset(data) print(data) a. 34 [15, 0, 47, 12, 0] b. [15, 34, 47, 12, 0] [15, 34, 47, 12, 0] c. 34 [15, 34, 47, 12, 0] d. [15, 0, 47, 12, 0] [15, 0, 47, 12, 0]

b. [15, 34, 47, 12, 0] [15, 34, 47, 12, 0]

What is output? new_list = [223, 645, 500, 10, 22] new_list.sort() for i in new_list: ind = new_list.index(i) if ind > 0: new_list[ind-1] += i print(new_list) a. [868, 1145, 510, 32, 22] b. [32, 245, 723, 1145, 645] c. [22, 32, 510, 1145] d. [10, 22, 223, 500, 645]

b. [32, 245, 723, 1145, 645]

What code replaces XXX to make the program output the number 10? multiplier = 1 def do_multiplication(x): return x * multiplier def set_multiplier(x): XXX multiplier = x user_value = 5 set_multplier(2) print(do_multiplication(user_value)) a. set_multiplier(2) b. global multiplier c. global x d. do_multiplication(x)

b. global multiplier

What is the output? def gen_command(application, **kwargs): command = application for key in kwargs: value = kwargs[key] command += f' --{key}={value}' return command print(gen_command('ls', color='always', sort='size',format='long')) a. ls color=always sort=size format=long b. ls --color=always --sort=size --format=long c. ls color='always' sort='size' format='long' d. ls --'color'='always' --'sort'='size' --'format'='long'

b. ls --color=always --sort=size --format=long

Select the option to get the value of temperature from the dictionary my_dict ={'Country':'India', 'State': {'City':'Delhi', 'Temperature':40}}. a. my_dict[1][1] b. my_dict['State']['Temperature'] c. my_dict.State.Temperature d. My_dict[4]

b. my_dict['State']['Temperature']

What is the output? for i in range(11): if i == 6: continue else: print(i, end=' ') a. 0 1 2 3 4 5 b. 0 1 2 3 4 5 6 c. 0 1 2 3 4 5 7 8 9 d. 0 1 2 3 4 5 7 8 9 10

d. 0 1 2 3 4 5 7 8 9 10

What is output? mydict = {x: x*x for x in range(0, 5)} for data in mydict.values(): print(data, end=' ') a. 0 1 4 9 16 b. (0, 0) (1, 1) (2, 4) (3, 9) (4, 16) c. 1 4 9 1 6 2 5 d. 0 1 4 9 16

d. 0 1 4 9 16

What is the output? id_list = [13, 984, 231, 140] for id in id_list: if id != 231: print(id, end=' ') else: print('Done') a. Done b. 13 984 Done c. 13 984 231 140 Done d. 13 984 140 Done

d. 13 984 140 Done

How many times does the following loop iterate? i = 0 while i <= 100: print(i) i = i + 2 a. 0 b. 49 c. 50 d. 51

d. 51

What initial value of x will cause an infinite loop? x = int(input()) while x != 0: x = x - 2 print(x) a. 0 b. 2 c. 4 d. 7

d. 7

What is the output? count = 0 while count < 3: print('loop') count = count + 1 print(f'Final value of count: {count}') a. Prints 'loop' once, then 'final value of count: 1' b. Prints 'loop' three times, then 'final value of count: 3' c. Prints 'loop' three times, then 'final value of count: 4' d. Prints 'loop' forever (infinite loop)

d. Prints 'loop' forever (infinite loop)

What is output? dict = {1: 'X', 2: 'Y', 3: 'Z'} print(dict.get(2, 'A')) a. Z b. A c. Error, invalid syntax d. Y

d. Y

What is output? my_var = ['python'] my_list = my_var[0].split() my_list += 'world' del my_list[1] print(my_list) a. ['p', 't', 'h', 'o', n', 'w', 'o', 'r', 'l', 'd'] b. ['python', 'orld'] c. ['python'] d. ['python', 'o', 'r', 'l', 'd']

d. ['python', 'o', 'r', 'l', 'd']

What is the value of new_list? my_list = [1, 2, 3, 4] new_list = [i**2 for i in my_list] a. [2, 4, 6, 8] b. [1, 2, 3, 4] c. [1, 2, 3, 4, 1, 2, 3, 4] d. [1, 4, 9, 16]

d. [1, 4, 9, 16]

Complete the code to generate (16, 4) as the output. class Exponents: def __init__(self, a = 1, b = 1): self.a = a self.b = b def __pow__(self, other): XXX e1 = Exponents (4, 2) e2 = Exponents(2, 2) print(e1 ** e2) a. a = other.a ** other.a b = self.b ** self.b return(a, b) b. a = self.a ** self.a b = other.b ** other.b return(a, b) c. a = self.a * other.a b = self.b * other.b return(a, b) d. a = self.a ** other.a b = self.b ** other.b return(a, b)

d. a = self.a ** other.a b = self.b ** other.b return(a, b)

Complete the code below to produce 'Student Name: ABC' and 'Student Age: 10' as the output.XXX student1 = Student() student1.age = 10 print(f'Student Name: {student1.name}\n Student Age:{student1.age}') a. class student1: def __init__(self): self.name = 'Student Name' self.age = '10' b. class student1: def __init__(self): self.name = 'ABC' self.age = 10 c. class Student: def __init__(self): self.name = ABC self.age = 10 d. class Student: def __init__(self): self.name = 'ABC' self.age = 10

d. class Student: def __init__(self): self.name = 'ABC' self.age = 10

In the code below, identify the correct instantiation of a new class object. class Subtract: def __init__(self, num1, num2): self.num1= num1 self.num2 = num2 def calculate_diff(self): diff = self.num1 - self.num2 print(diff) a. diff1 = Subtract() b. diff1.calculate_diff(25, 10) c. diff1.calculate_diff() d. diff1 = Subtract(25, 10)

d. diff1 = Subtract(25, 10)

Consider the list my_list = ['www', 'python', 'org']. Choose the option that returns 'www.python.org' as the value to my_string. a. my_string = (.).join(my_list) b. my_string = ','.join(my_list) c. my_string = (' ').join(my_list) d. my_string = ('.').join(my_list)

d. my_string = ('.').join(my_list)

Consider my_string = 'roy came third in the running race'. Which option will return 'Roy came 3rd in the running race' as the value of new_string? a. new_string = my_string.title()new_string = new_string.replace('thi', '3') b. new_string = my_string[:3].title()new_string = new_string.replace('thi', '3') c. new_string = my_string.capitalize()new_string = new_string.replace('third', '3') d. new_string = my_string.capitalize()new_string = new_string.replace('thi', '3')

d. new_string = my_string.capitalize()new_string = new_string.replace('thi', '3')

Which XXX completes the find_smallest() function? def find_smallest(a, b, c): if a <= b and a <= c: smallest = a elif b <= a and b <= c: smallest = b elif c <= a and c <= b: smallest = c XXX result = find_smallest(7, 4, 8) print(result) a. return a b. return b c. return c d. return smallest

d. return smallest


Related study sets

When to Rob a Bank, with Freakonomics' Stephen J. Dubner

View Set

Biochem Quiz 3 Study: Prokaryotes & Eukaryotes

View Set

Science and Engineering Practices

View Set

chapter 8 international business practice

View Set