python查询水果价格_C语言查询水果价格
时间: 2023-07-09 12:22:15 浏览: 203
对于Python查询水果价格,你可以使用以下代码:
```python
fruit_prices = {"apple": 0.5, "banana": 0.3, "orange": 0.4}
fruit = input("请输入水果名称:")
if fruit in fruit_prices:
print("{}的价格是{}元/斤".format(fruit, fruit_prices[fruit]))
else:
print("很抱歉,我们暂时没有{}的价格信息。".format(fruit))
```
对于C语言查询水果价格,你可以使用以下代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char fruit[10];
float price;
printf("请输入水果名称:");
scanf("%s", fruit);
if (strcmp(fruit, "apple") == 0) {
price = 0.5;
} else if (strcmp(fruit, "banana") == 0) {
price = 0.3;
} else if (strcmp(fruit, "orange") == 0) {
price = 0.4;
} else {
printf("很抱歉,我们暂时没有%s的价格信息。\n", fruit);
return 0;
}
printf("%s的价格是%.2f元/斤\n", fruit, price);
return 0;
}
```
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)