Python 除法产生的答案比应有的大?
Python division yielding larger answers than it should?
我正在尝试在 Python 中制作一个计算器,它可以计算出光传播 X 英里所需的时间,但我遇到了一些除法问题。
当我输入“1”或任何较小的数字时,它会给我一个比应有的更大的数字。例如,我输入“5”,它告诉我 "It would take 2.684096876850903e-05 seconds for light to travel 5.0 miles.",即使它只需要 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("");
你给出的两个答案是一样的,一个是科学计数法,一个是标准计数法。
例如:
0.00000000851 == 8.51e-9
我正在尝试在 Python 中制作一个计算器,它可以计算出光传播 X 英里所需的时间,但我遇到了一些除法问题。
当我输入“1”或任何较小的数字时,它会给我一个比应有的更大的数字。例如,我输入“5”,它告诉我 "It would take 2.684096876850903e-05 seconds for light to travel 5.0 miles.",即使它只需要 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("");
你给出的两个答案是一样的,一个是科学计数法,一个是标准计数法。
例如:
0.00000000851 == 8.51e-9