用 Deepseek 写的 html+js 孩子身高预测

 

算法验证

根据您提供的测试数据:

  • 父亲身高:187cm

  • 母亲身高:177cm

  • 预测男孩身高:(187+177)×1.08÷2 = 196.6cm

确实,这个结果看起来偏高。让我们分析一下:

  1. 公式来源

    • 这个公式是较为简化的遗传身高预测法

    • 实际医学上更常用的是以下公式:

      • 男孩身高 = (父亲身高 + 母亲身高 + 13cm) ÷ 2

      • 女孩身高 = (父亲身高 + 母亲身高 - 13cm) ÷ 2

  2. 用医学常用公式计算

    • 男孩身高 = (187 + 177 + 13) ÷ 2 = 188.5cm

    • 这个结果看起来更合理

  3. 原公式问题

    • 原公式中的1.08系数会使结果偏高约8%

    • 这可能解释了为什么预测结果达到196.6cm

改进建议

我建议使用更被医学界认可的公式,以下是改进后的代码:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>孩子身高预测工具(改进版)</title>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            max-width: 500px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        h1 {
            color: #2c3e50;
            text-align: center;
        }
        .container {
            background-color: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
        }
        button:hover {
            background-color: #2980b9;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            background-color: #e8f4fc;
            border-radius: 4px;
            display: none;
        }
        .note {
            margin-top: 20px;
            font-size: 14px;
            color: #7f8c8d;
            text-align: justify;
        }
        .range {
            margin-top: 10px;
            font-weight: bold;
            color: #2c3e50;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>孩子身高预测工具(改进版)</h1>
        
        <div class="form-group">
            <label for="gender">孩子性别</label>
            <select id="gender">
                <option value="boy">男孩</option>
                <option value="girl">女孩</option>
            </select>
        </div>
        
        <div class="form-group">
            <label for="fatherHeight">父亲身高 (厘米)</label>
            <input type="number" id="fatherHeight" placeholder="请输入父亲身高">
        </div>
        
        <div class="form-group">
            <label for="motherHeight">母亲身高 (厘米)</label>
            <input type="number" id="motherHeight" placeholder="请输入母亲身高">
        </div>
        
        <button onclick="calculateHeight()">预测身高</button>
        
        <div id="result" class="result">
            <h3>预测结果</h3>
            <p>预测身高约为: <span id="predictedHeight"></span> 厘米</p>
            <p class="range">可能范围: <span id="heightRange"></span> 厘米</p>
        </div>
        
        <div class="note">
            <p><strong>说明:</strong></p>
            <p>1. 此工具采用医学常用身高预测公式计算</p>
            <p>2. 男孩身高 = (父亲身高 + 母亲身高 + 13cm) ÷ 2</p>
            <p>3. 女孩身高 = (父亲身高 + 母亲身高 - 13cm) ÷ 2</p>
            <p>4. 预测结果包含±5cm的浮动范围</p>
            <p>5. 孩子身高受遗传(70%)和环境因素(30%)共同影响,因此仅供参考</p>
        </div>
    </div>

    <script>
        function calculateHeight() {
            // 获取输入值
            const gender = document.getElementById('gender').value;
            const fatherHeight = parseFloat(document.getElementById('fatherHeight').value);
            const motherHeight = parseFloat(document.getElementById('motherHeight').value);
            
            // 验证输入
            if (isNaN(fatherHeight) || isNaN(motherHeight) || fatherHeight <= 0 || motherHeight <= 0) {
                alert('请输入有效的父母身高数值!');
                return;
            }
            
            let predictedHeight;
            
            // 根据性别计算预测身高
            if (gender === 'boy') {
                // 男孩公式: (父亲身高 + 母亲身高 + 13) ÷ 2
                predictedHeight = (fatherHeight + motherHeight + 13) / 2;
            } else {
                // 女孩公式: (父亲身高 + 母亲身高 - 13) ÷ 2
                predictedHeight = (fatherHeight + motherHeight - 13) / 2;
            }
            
            // 显示结果
            document.getElementById('predictedHeight').textContent = predictedHeight.toFixed(1);
            document.getElementById('heightRange').textContent = 
                (predictedHeight - 5).toFixed(1) + " - " + (predictedHeight + 5).toFixed(1);
            document.getElementById('result').style.display = 'block';
        }
    </script>
</body>
</html>
  1. 改用更合理的公式

    • 男孩:(父亲身高 + 母亲身高 + 13cm) ÷ 2

    • 女孩:(父亲身高 + 母亲身高 - 13cm) ÷ 2

  2. 用您的数据重新计算

    • (187 + 177 + 13) ÷ 2 = 188.5cm

    • 可能范围:183.5-193.5cm

    • 这个结果更符合实际情况

  3. 新增功能

    • 显示可能的身高范围(±5cm)

    • 更详细的说明文字

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值