题目详情
单选题 设小明正在编写一个电子商务网站的购物车功能,需要处理商品和其价格的信息.如果小明想通过商品名称来查找其价格,以下哪段Python代码是正确的
A. ```python products = {"Product A": 10.99, "Product B": 20.49, "Product C": 5.99} product_name = "Product B" product_price = products[product_name] ```
B. ```python products = ["Product A", "Product B", "Product C"] prices = [10.99, 20.49, 5.99] product_name = "Product B" product_price = prices[products.index(product_name)] ```
C. ```python products = ["Product A", "Product B", "Product C"] prices = [10.99, 20.49, 5.99] product_name = "Product B" product_price = prices.find(product_name) ```
D. ```python products = ["Product A", "Product B", "Product C"] prices = [10.99, 20.49, 5.99] product_name = "Product B" product_price = prices[product_name] ```

学科:Python程序设计基础
时间:2024-12-24 12:48:35
相关题目
相关作业
