pta查询查找名称为“apple”的水果的价格
时间: 2025-03-29 16:11:20 浏览: 80
### 苹果的价格查询
根据已知的信息,苹果(apple)的单价为每公斤3.00元[^1]。因此,对于用户查询的水果“苹果”,其价格应按照如下格式输出:
```plaintext
price = 3.00
```
以下是实现该功能的一个简单 Python 程序示例,用于模拟水果价格查询过程并满足指定条件:
```python
def query_fruit_price():
fruits = {
1: ("apple", 3.00),
2: ("pear", 2.50),
3: ("orange", 4.10),
4: ("grape", 10.20)
}
print("[1] apple [2] pear [3] orange [4] grape [0] exit")
count = 0
while True:
user_input = int(input("请输入要查询的水果编号:"))
if user_input == 0 or count >= 5:
break
if user_input in fruits:
fruit_name, price = fruits[user_input]
print(f"price = {price:.2f}")
else:
print("price = 0.00")
count += 1
query_fruit_price()
```
上述代码实现了基于编号的水果价格查询逻辑,并遵循了连续查询不超过五次或手动退出的要求。
####
阅读全文
相关推荐




















