输入身高和体重,将其转换为米和斤,然后计算体指数并输出结果。 示例代码: height = float(input("请输入身高(厘米):")) / 100 weight = float(input("请输入体重(公斤):")) print("身高:{:.2f}米".format(height)) print("体重:{:.2f}斤".format(weight * 2)) t = weight / (height * height) print("体指数:{:.2f}".format(t))
时间: 2024-01-21 21:20:08 浏览: 39
好的,这是一个简单的身高体重转换和计算BMI的Python代码:
```
height = float(input("请输入身高(厘米):")) / 100
weight = float(input("请输入体重(公斤):")) * 2
print("身高:{:.2f}米".format(height))
print("体重:{:.2f}斤".format(weight))
bmi = weight / (height ** 2)
print("体指数:{:.2f}".format(bmi))
```
输入身高和体重后,程序会先将身高转换为米,体重转换为斤,然后输出转换后的结果。接着,程序用转换后的身高体重计算BMI,并输出结果。
相关问题
用c语言编程 计算体指数 从键盘输入某人的身高(以厘米为单位,如174cm)和体重(以公斤为单位,如70公斤),将身高(以米为单位,如1.74m)和体重(以斤为单位,如140斤)输出在屏幕上,并按照以下公式计算并输出体指数,要求结果保留到小数点后2位。 假设体重为w公斤,身高为h米,则体指数的计算公式为:t=w/(h*h) 以下是程序的输出示例: Input weight, height: 70,174 weight=140 height=1.74 t=23.12 输入格式: "%d,%d" 输入提示信息:"Input weight, height:\n" (注意:在height和逗号之间有一个空格) 体重输出格式:"weight=%d\n" 身高输出格式:"height=%.2f\n" 体指数输出格式:"t=%.2f\n"
好的,以下是C语言的程序代码:
```c
#include <stdio.h>
int main()
{
int weight, height;
float h, t;
printf("Input weight, height:\n");
scanf("%d,%d", &weight, &height);
h = height / 100.0; // 将身高从厘米转换为米
printf("weight=%d\n", weight * 2); // 将体重从公斤转换为斤
printf("height=%.2f\n", h);
t = weight / (h * h);
printf("t=%.2f\n", t);
return 0;
}
```
运行程序后,输入身高和体重后,输出的结果为:
```
Input weight, height:
70,174
weight=140
height=1.74
t=23.12
```
其中,体重乘以2是因为题目要求将体重从公斤转换为斤。
计算体指数 从键盘输入某人的身高(以厘米为单位,如174cm)和体重(以公斤为单位,如70公斤),将身高(以米为单位,如1.74m)和体重(以斤为单位,如140斤)输出在屏幕上,并按照以下公式计算并输出体指数,要求结果保留到小数点后2位。 假设体重为w公斤,身高为h米,则体指数的计算公式为:t=w/(h*h) 以下是程序的输出示例: Input weight, height: 70,174↙ weight=140 height=1.74 t=23.12C语言
以下是实现该功能的 C 语言代码:
```c
#include <stdio.h>
int main() {
int weight, height_cm;
float height_m, t;
printf("Input weight, height: ");
scanf("%d,%d", &weight, &height_cm);
// 将身高单位从厘米转换为米
height_m = height_cm / 100.0;
printf("weight=%d height=%.2fm ", weight * 2, height_m);
// 计算体指数
t = weight / (height_m * height_m);
printf("t=%.2f", t);
return 0;
}
```
运行结果:
```
Input weight, height: 70,174
weight=140 height=1.74m t=23.12
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)