当前位置:网站首页>【GoLang】通过BMI指数学习控制台输入与条件控制
【GoLang】通过BMI指数学习控制台输入与条件控制
2022-06-10 09:39:00 【华为云】
前言
示例提要
BMI公式
BMI对照表
第一部分 控制台输入
// 单个字符串输入package mainimport "fmt"func main() { fmt.Println("请输入String类型的数据: ") var test_str string fmt.Scan(&test_str) fmt.Println("你的输入是:",test_str)}// 多种类型数据package mainimport "fmt"func main() { // float64类型 fmt.Println("请输入float64类型的数据: ") var test_float float64 fmt.Scan(&test_float) fmt.Println("你的输入是:",test_float) // int类型 fmt.Println("请输入int类型的数据: ") var test_int int fmt.Scan(&test_int) fmt.Println("你的输入是:",test_int) // bool类型 fmt.Println("请输入bool类型的数据: ") var test_bool bool fmt.Scan(&test_bool) fmt.Println("你的输入是:",test_bool)}package mainimport "fmt"func main() { fmt.Println("请输入你的身高(m): ") var height float64 fmt.Scan(&height) fmt.Println("你的身高(m)是:",height) fmt.Println("请输入你的体重(KG): ") var weight float64 fmt.Scan(&weight) fmt.Println("你的体重(KG)是:",weight) var bmi_num float64 = weight/(height*height) fmt.Println("你的BMI指数是: ",bmi_num) // 控制台输出BMI指数}
第二部分 条件控制
package mainimport "fmt"func main() { if true { fmt.Println("条件为True时执行: ") } if false { fmt.Println("条件为false时不执行: ") }}package mainimport "fmt"func main() { fmt.Println("请输入你的身高(m): ") var height float64 fmt.Scan(&height) fmt.Println("你的身高(m)是:",height) fmt.Println("请输入你的体重(KG): ") var weight float64 fmt.Scan(&weight) fmt.Println("你的体重(KG)是:",weight) var bmi_num float64 = weight/(height*height) fmt.Println("你的BMI指数是: ",bmi_num) // 控制台输出BMI指数 var bmi_status string if bmi_num < 18.5 { bmi_status = "消瘦" }else if bmi_num > 18.5 && bmi_num < 24.9 { bmi_status = "正常" }else if bmi_num > 25 && bmi_num < 27.9 { bmi_status = "超重" }else if bmi_num > 28 { bmi_status = "肥胖" } fmt.Println("你的BMI健康状态为: ",bmi_status)}边栏推荐
- 隐私计算重要技术突破!亿级数据密态分析可在10分钟内完成
- How about the course system of PHP
- 53. 最大子数组和
- R语言plotly可视化:plotly可视化箱图、使用quartilemethod参数自定义设置箱图分位数的计算方法(Basic Boxplot)
- Flutter 一行Row中显示RadioListTile
- 程序编译基本过程
- HMM details + examples
- Example 2 of lambda expression
- R语言coin包应用于独立性问题的置换检验(permutation tests)、在同一数据集上使用单向方差分析(one-way ANOVA)和近似的K样本置换检验、比较多个分组的均值是否相同
- [fishing artifact] UI library second to second lowcode tool - list part (II) small tool for maintaining JSON
猜你喜欢

Using requests library to crawl web pages to obtain data

程序编译基本过程
![[fishing artifact] UI library second to second lowcode tool - list part (II) small tool for maintaining JSON](/img/14/f14d02363f527b794e8960011541f5.png)
[fishing artifact] UI library second to second lowcode tool - list part (II) small tool for maintaining JSON

solr高級查詢應用---按字段分組查詢

P1387 最大正方形(dp)

416. segmentation and subsets

mmclassification

隐私计算重要技术突破!亿级数据密态分析可在10分钟内完成

Someone used this Tiktok e-commerce marketing method to win an offer with a monthly salary of 2W

795 D Max GEQ sum (monotone stack +rmq)
随机推荐
GNSS positioning data collection
PostgreSQL cost model
PostMessage,SendMessage跨不同权限进程通信
On the night of the joint commissioning, I beat up my colleagues
Example 3 of lambda expression
R语言使用lmPerm包应用于线性模型的置换方法(置换检验、permutation tests)、使用lm模型构建多项式回归模型、使用lmp函数生成置换检验多项式回归模型
阅读笔记 PointNet: Deep Learning on Point Sets for 3D Classification and Segmentation
PostgreSQL 代价模型
How to Spot-Check Classification Algorithms
MySQL数据库(26):视图 view
Pycocotools online installation -- [available]
使用 nsenter 进入 netns 抓包
[Blue Bridge Cup training 100 questions] scratch apple is ripe blue bridge cup scratch competition special prediction programming question intensive training simulation exercise question 13
618来袭,大量优惠券生成太耗时?ThreadPoolTaskExecutor线程池帮你来搞定
#795 D Max GEQ Sum(单调栈+RMQ)
What should we pay attention to when developing, designing and building the reward task source code
No module named ‘pyautogui‘
[fishing artifact] UI library second to second lowcode tool - list part (II) small tool for maintaining JSON
pip install . And pip install -e Differences between
SOLR Advanced Query Application - - Grouper les requêtes par champ