0

I am trying to make a calculator in Python that gives you the amount of time it would take for light to travel X miles, but I'm having some division problems.

When I input "1" or any small number, it gives me a larger number than it should. For example, I input "5" and it tells me "It would take 2.684096876850903e-05 seconds for light to travel 5.0 miles.", even though it only takes 0.00002684096877 seconds. What's odd is the calculator actually works with large numbers. (For example, I input milesPerSecond and it gives me "1", like it should.)

Is there something I am doing wrong? Thanks.

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("");
AndyG
  • 39,700
  • 8
  • 109
  • 143
Alexcamostyle
  • 3,623
  • 4
  • 14
  • 13
  • 6
    Just note that `2.684096876850903e-05` is equal to `0.00002684096877` – Bhargav Rao Jan 19 '15 at 18:36
  • Take a look at https://docs.python.org/2/library/string.html#format-string-syntax to change the how the value looks. – AMacK Jan 19 '15 at 18:38
  • This question may be off-topic because it was caused by a misinterpretation of the output; the code in question works as intended. Possibly related to [this question](http://stackoverflow.com/q/658763/2069350). – Henry Keiter Jan 19 '15 at 21:08

1 Answers1

1

The two answers you show are the same, one is in scientific notation, the other is in standard notation.

For example:

0.00000000851  ==  8.51e-9
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Derek_6424246
  • 237
  • 3
  • 12