题目
题目
单项选择题

Question at position 15 Two functions for calculating the total cost and the change given in a transaction are provided. If the missing lines are filled in correctly, the program should prompt the user to input the cost of an item, the quantity, and the amount paid, and then display the change that should be returned. [table] 1  def total_cost(item_cost: float, quantity: int) -> float:2 return item_cost * quantity3 4 def change_given(payment: float, total_cost: float) -> float:5 return payment - total_cost6 7 def main():8 item_cost = float(input('Enter the cost of the item: '))9 quantity = int(input('Enter the quantity of the items: '))10 payment = float(input('Enter the payment amount: '))11 12 result_1 = # ( code WILL go here )13 result_2 = # ( code WILL go here )14 15 print(f'Total cost: {result_1:.2f}')16 print(f'Change due: {result_2:.2f}')17 18 main() [/table] Which of the following options is the correct missing code? (Code filled in has been bolded.) 12 result_1 = total_cost(payment, quantity)13 result_2 = change_given(quantity, payment)12 result_1 = change_given(payment, item_cost)13 result_2 = total_cost(quantity, item_cost)12 result_1 = change_given(item_cost, payment)13 result_2 = total_cost(result_1, quantity)12 result_1 = total_cost(item_cost, quantity)13 result_2 = change_given(payment, result_1)Clear my selection

选项
A.12          result_1 = total_cost(payment, quantity) 13          result_2 = change_given(quantity, payment)
B.12          result_1 = change_given(payment, item_cost) 13          result_2 = total_cost(quantity, item_cost)
C.12          result_1 = change_given(item_cost, payment) 13          result_2 = total_cost(result_1, quantity)
D.12          result_1 = total_cost(item_cost, quantity) 13          result_2 = change_given(payment, result_1)
查看解析

查看解析

标准答案
Please login to view
思路分析
We start by understanding what the program is supposed to do: it defines two functions, total_cost(item_cost, quantity) -> item_cost * quantity and change_given(payment, total_cost) -> payment - total_cost, then in main it collects item_cost, quantity, and payment, computes two results, and prints Total cost and Change due. The missing lines correspond to filling result_1 with the total cost and result_2 with the change, using the correct function calls and argument order. Option A: 12 result_1 = total_cost(payment, quantity) 13 result_2 = change_given(q......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!