Python部门产生的答案应该超出应有的范围?

时间:2015-01-19 18:34:41

标签: python division

我正在尝试用Python制作一个计算器,它可以为你提供光线行进X英里所需的时间,但我遇到了一些分裂问题。

当我输入“1”或任何小数字时,它会给我一个比它应该更大的数字。例如,我输入“5”并且它告诉我“光需要2.684096876850903e-05秒才能行驶5.0英里。”,即使只需要0.00002684096877秒。奇怪的是,计算器实际上适用于大数字。 (例如,我输入milesPerSecond,它给我“1”,就像它应该的那样。)

我做错了吗?感谢。

variable = 1
while variable == 1:
    input1 = input("How many miles do you want light to travel? ");
    miles = float(input1);
    milesPerSecond = 186282.397;
    seconds = miles / milesPerSecond;
    if seconds < 60:
        print("It would take", seconds, "seconds for light to travel", miles, "miles.");
    elif seconds < 3600:
        print("It would take", seconds / 60, "minutes for light to travel", miles, "miles.");
    elif seconds < 86400:
        print("It would take", seconds / 3600, "hours for light to travel", miles, "miles.");
    elif seconds > 86400:
        print("It would take", seconds / 86400, "days for light to trabel", miles, "miles.");
    print("");

1 个答案:

答案 0 :(得分:1)

您展示的两个答案是相同的,一个是科学记数法,另一个是标准记法。

例如:

0.00000000851  ==  8.51e-9