Study

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

After a function's last statement is executed, the program returns to the next line after the _____. A function call B import statement C start of the program D function definition

A

Complete the following code to get 'Email me at [email protected] or call at 333 222 1111' as output. email = 'Email: [email protected]' phone = 'Ph: 333-222-1111' print(f"Email me at {XXX} or call at {YYY}") A XXX: email.split(' ')[1], YYY: ' '.join((phone.split(': ' )[1]).split('-')) B XXX: email.split(' '), YYY: ' '.join((phone.split(': ' )[1])) C XXX: email.split(' ')[0], YYY: ' '.join((phone.split(': ' )[0].split('-'))) D XXX: email.split(' '), YYY: ' '.join((phone.split(': ' )))

A

Fill in the blank so that the loop displays all odd numbers from 1 to 100. i = 1 while i <= 100: print(i) i = _____ A i + 2 B. i + 1 C 2 D 1

A

For the given pseudocode, which XXX and YYY will output the sum of the input integers (stopping when -1 is input)? Choices are in the form XXX / YYY. val = Get next input XXX While val is not -1 YYY val = Get next input Put sum to output A sum = 0 / sum = sum + val B sum = val / sum = val C sum = val / sum = sum + val D sum = 0 / sum = val

A

How do you obtain a list of tuples of key-value pairs in a dictionary dict? A dict.items() B dict.values() C dict.get(key, default) D dict.keys()

A

What is output? new_list = [10, 20, 30, 40, 50] for i in new_list: print(i * 2) A 20 40 60 80 100 B [20, 40, 60, 80, 100] C 10 10 20 20 30 30 40 40 50 50 D [10, 20, 30, 40, 50, 10, 20, 30, 40, 50]

A

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 ['HDMI'] Samsung monitor ['HDMI', 'HDMI'] B No output: using a list as a default argument is an error C Acer monitor ['HDMI'] Samsung monitor ['HDMI'] D Acer monitor Samsung monitor

A

What is the output? def find_sqr(a): t = a * a return t square = find_sqr(10) print(square) A 100 B 10 C (Nothing is outputted)

A

Choose the correct syntax to complete the code below in order to print [1, 2, 3, 4, 5] as the output. my_list = [3, 2, 5] XXX print(my_list) A my_list.insert(0, [1,4]) my_list.sort() B my_list.extend([1, 4]) my_list.sort() C my_list.append([1, 4]) my_list.sort() D my_list.sort() my_list.append([1, 4])

B

Consider the lists my_list = [['The', 'Magic'] , ['Rhonda', 'Byrne']] and new_list = [] . Select the option that will produce 'The Magic : Rhonda Byrne' as the output. for i, j in enumerate(my_list): new_list = my_list[i] print(f'{new_list[0]} {new_list[1]}: {new_list[2]} {new_list[3]}') for i, j in enumerate(my_list): for item in my_list[i]: new_list.append(item) print(f'{new_list[0]} {new_list[1]}: {new_list[2]} {new_list[3]}') for i, j in enumerate(my_list): new_list.append(j) print(f'{new_list[0]} {new_list[1]}: {new_list[2]} {new_list[3]}') for i, j in enumerate(my_list): new_list = j print(f'{new_list[0]} {new_list[1]}: {new_list[2]} {new_list[3]}')

B

What is output? my_string = 'Greetings!' print(my_string == 'greetings!') print('tin' in my_string) print('Hello' > my_string) A True True True B False True False C False True True D True True False

C

What will be output for print(f'{1.6180339:.5f}')? A '1.6180' B '00001.6180' C '1.61803' D '00001.61803'

C

Identify all the keys (including nested dictionaries) in students = {'Semester_1' : {'Aston':20, 'Julia':25}, 'Semester_2' : {'Ben':21, 'Lisa':26}} . A Semester_1, Semester_2, Aston, Julia, Ben, and Lisa B Aston, Julia, Ben, and Lisa C Semester_1 and Semester_2 D 20, 25, 21, and 26

a (CHECK

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 9 B 4 C 6 D 36

B

How many times does the following loop iterate? i = 5 while i < 10: print(i) i = i + 1 5 4 0 6

A

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

A

The following program prints the number of integers in my_list that are greater than the previous integer in the list. Which choice fills in the blank to complete the for loop? my_list = [ 3, 2, 7, 8, 6, 9 ] count = 0 for _____: if my_list[i] > my_list[i-1]: count = count + 1 print(count) A i in range(1, len(my_list)) B i in range(0, len(my_list)) Ci in range(0, len(my_list)+1) D i in range(1, len(my_list)+1)

A

What initial value of x will cause an infinite loop? x = int(input()) while x != 0: x = x - 2 print(x) A 7 B 2 C 4 D 0

A

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=' ') 0:0 1:1 4:2 9:3 16:4 4:16 3:9 2:4 1:1 0:0 0:0 1:1 2:2 3:3 4:4 16:4 9:3 4:2 1:1 0:0

A

What is the value of kv_List? kv_List = [{'k': {'v': 2}}, {'k': {'v': 15}}, {'k': {'v': 8}}] kv_List.sort(key=lambda e: e['k']['v'], reverse=True) A [{'k': {'v': 15}}, {'k': {'v': 8}}, {'k': {'v': 2}}] B [{'k': {'v': 10}}, {'k': {'v': 15}}, {'k': {'v': 2}}] C [{'k': {'v': 2}}, {'k': {'v': 8}}, {'k': {'v': 15}}] D [{'k': {'v': 8}}, {'k': {'v': 15}}, {'k': {'v': 2}}]

A

What is the value of sys.argv[1]+len(sys.argv[1]) for the command-line input > python prog.py 121 ? A Runtime error B 1213 C 121 D 124

A

Which choice fills in the blank so that the output prints one line for each item in sports_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

A

Which is an essential feature of a while loop having the following form? while loop_expression: loop_body A The loop_expression should be affected by the loop_body B The loop_expression should not be affected by the loop_body C The loop_body should update at least two variables D The loop_body should get user input

A

Fill in the blank so that the output is a count of how many negative values are in temperatures? temperatures = [-2, 8, 4, -7, 18, 3, -1] count = 0 for t in temperatures: if _____: count = count + 1 print(f'Total negative temperatures: {count}') A t[temperatures] < 0 B t < 0 C temperatures < 0 D temperatures[t] < 0

B

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'] Cmy_dict.State.Temperature

B

What is output? new_list =[10, 20, 30, 40] for i in range(len(new_list)): if new_list[i] != new_list[-1]: new_list[i] *= 2 print(new_list) A [10, 20, 30, 40, 10, 20, 30, 40] B [20, 40, 60, 40] C [20, 40, 60, 40, 20, 40, 60, 40] D [10, 20, 30, 40]

B

What is output? new_string = 'One giant leap for mankind' print(new_string[0:6]) A One gia B One gi C Onegi D Onegia

B

What is the output? count = 0 while count < 3: print('loop') count = count + 1 print(f'Final value of count: {count}') A Prints 'loop' three times, then 'final value of count: 4' B Prints 'loop' forever (infinite loop) C Prints 'loop' three times, then 'final value of count: 3' D Prints 'loop' once, then 'final value of count: 1

B

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 13 984 231 140 Done B 13 984 140 Done C 13 984 Done D Done

B

What is the output? names = [ 'Gerry', 'Preet', 'Jimin', 'Susan' ] index = 0 while index < len(names): if names[index] == 'Susan': break else: index += 1 else: print('Done') print(index) A Done B 3 C 4 D 3 Done

B

Which of the following code blocks produces the output given below? ['odd', 'even', 'odd', 'even'] A new_list = [3, 4, 5, 6] for i in new_list: if new_list[i] % 2 == 0: new_list[i] = 'even' else: new_list[i] = 'odd' print(new_list) B new_list = [3, 4, 5, 6] for i in range(len(new_list)): if new_list[i] % 2 == 0: new_list[i] = 'even' else: new_list[i] = 'odd' print(new_list) C new_list = [3, 4, 5, 6] ' for i in new_list: if i % 2 == 0: i = 'even' else: i == 'odd' print(new_list) D new_list = [3, 4, 5, 6] for i in range(len(new_list)): if i % 2 == 0: new_list[i] = 'even' else: new_list[i] = 'odd' print(new_list[i])

B

What is the output? c1 = 'c' while c1 > 'a': for i in range(3): print(f'{c1}{i}', end=' ') c1 = chr(ord(c1) - 1) A c1 c2 c3 b1 b2 b3 B c0 c1 c2 b0 b1 b2 C c2 c1 c0 b2 b1 b0 D c0 c1 c2 b0 b1 b2 a0 a1 a2

B CHECK AGAIN LATER

Consider the string new_string = 'Code development in Python'. Which statement will return 'velop' as a substring? new_string[-18:12] new_string[7:11] new_string[-19:12] new_string[8:12]

C

Standard Python functions such as int(), range() etc. are part of the _____ scope. ALocal B Internal C Built-in D Global

C

What defines the minimum number of characters that must be inserted into the string? A field length B string length C field width D string width

C

What is a possible output? rentals = { 'skis' : 20.00, 'boots' : 10.00, 'skates' : 4.00 } for x in rentals: print(x, end=' ') A 20.00 10.00 4.00 B skis: 20.00 boots: 10.00 skates: 4.00 C skis boots skates D x x x

C

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 False True True B True True True C True False False D False False False

C

What is output? new_string = 'Python' my_index = 0 while my_index != len(new_string)/2: print(new_string[my_index:int(len(new_string)/2)]) my_index += 1 A Pyt Pyt Pyt B hon thon ython C Pyt yt t D hon hon hon

C

Which function call would cause an output error? def print_product(product_name, product_id, cost): print(f'{product_name} (id: #{product_id}) - ${cost:.2f}') A print_product('Speakers', cost=32.99, product_id=21224) B print_product('Speakers', 21224, 32.99) C print_product('Speakers', 32.99, 21224) D print_product(product_id=21224, product_name='Speakers', cost=32.99)

C

Which line of the function has an error? def compute_sum_of_squares(num1, num2): # Line 1 sum = (num1 * num1) + (num2 * num2) # Line 2 return # Line 3 A Line 1 B Line 2 C Line 3 D None of the lines contains an error

C

Select the code that gives ['cat in a hat', 'fluffy dogs', 1989, 1990] as the output. Anew_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffy dogs'] print(new_list[-1:] + [1989, 1990]) B new_list = ['cat in a hat', 'fluffy dogs','1000', '2000', '3000'] print(new_list[-2:] + [1989, 1990]) C new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffy dogs'] print(new_list[-2:] + [1989, 1990]) D new_list = ['1000', '2000', '3000', 1989, 1990] print(new_list[-2:] + ['cat in a hat', 'fluffy dogs'])

C new_list = ['1000', '2000', '3000', 'cat in a hat', 'fluffy dogs'] print(new_list[-2:] + [1989, 1990])

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 size(students) B students.size() C students.len() D len(students)

D

Consider the string new_string = 'Berlin is the capital of Germany'. Which statement will return 'capital of Germany' as a substring? A new_string[14:31] B new_string[-18:1] C new_string[15:35] D new_string[-18:]

D

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 *<5, =<2 C *>4, <2 D *>4, =>2

D

How does the given function improve the code versus if no function was present? def fahrenheit_to_celsius(fahrenheit): return (fahrenheit - 32.0) * 5.0 / 9.0 fahrenheit = float(input()) c1 = fahrenheit_to_celsius(fahrenheit); c2 = fahrenheit_to_celsius(32.0); c3 = fahrenheit_to_celsius(72.0); A The use of the function makes the program run faster B The function does not improve the code C The use of the function reduces the number of variables in the code D The use of the function decreases redundant code

D

The process of searching namespaces for a name is called _____. A memory check B global search C variable lookup D scope resolution

D

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

D

What is output? mydict = {x: x*x for x in range(0, 5)} for data in mydict.values(): print(data, end=' ') A 1 4 9 16 25 B (0, 0) (1, 1) (2, 4) (3, 9) (4, 16) C 0 1 4 9 16 D 0 1 4 9 16

D

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 + 1 n = n + 1 3 5 1 4

D

What is the output? def is_even(num): if num % 2 == 0: even = True else: even = False is_even(7) print(even) A False B True C No output: Call to is_even() fails due to no return value D No output: An error occurs due to unknown variable even

D

What is the output? names = [ 'Gerry', 'Preet', 'Jimin', 'Susan' ] index = 0 while index < len(names): if names[index] == 'Susan': break else: index += 1 else: print('Done') print(index) A 4 B Done C 3 Done D 3

D

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 { 1: 'red', 2: 'green', 3: 'blue', 4: 'alpha'} B { 'items': { 1: 'red', 2: 'green', 3: 'blue', 4: 'yellow'}} C { 'items': 'colors'} D { 'items': { 1: 'red', 2: 'green', 3: 'blue', 4: 'alpha'}}

D

What sequence is generated by range(1, 10, 3) A 1 11 21 B 1 4 7 10 C 1 3 6 9 D 1 4 7

D

Which input value causes "Goodbye" to be output next? x = int(input()) while x >= 0: # Do something x = int(input()) print('Goodbye') A No such value B 0 C 1 D -1

D

_____ allows a function or operator to perform different tasks depending on the types of the arguments or operands. A Static typing B Prototyping C Type declaration D Polymorphism

D

num = 10; while num <= 15: print(num, end=' ') if num == 12: break num += 1 A 10 11 12 13 14 15 B 10 11 C 10 D 10 11 12

D

What is output? b1 = [7, 5, 9, 6] b1.sort() b2 = b1.copy() b1.append(10) b2 = b2[::-1] print(b1, b2) A [5, 6, 7, 9, 10] [5, 6, 7, 9, 10] B [5, 6, 7, 9, 10] [10, 9, 7, 6, 5] C [5, 6, 7, 9, 10] [9, 7, 6, 5] D [5, 6, 7, 9, 10] [5, 6, 7, 9]

DO LATER


Set pelajaran terkait

Chapter 13: Property, Plant, and Equipment: Depreciation and Depletion

View Set

AP Biology In Class Final Review (Part 1)

View Set

Economics Chapter 12 Practice Questions

View Set

Newton's First Law Test (Physics)

View Set

Загальна патологія (екзамен-крок)

View Set