[D. Evans] So here’s the Python expression to compute that. We’re multiplying the speed of light times 100cm in a meter times 1 divided by 1 billion. One nanosecond is 1 billionth of a second. You’ll note that I can’t have space in the numbers. It’s convenient when I write out the numbers to put spaces in them so we can see how big they are. Python doesn’t allow that. That looks like separate numbers if we have spaces there. That wouldn’t be valid in the Python grammar, so we can’t have the spaces there. So when we run this, we get the result 29.
That says it’s about 29cm that light travels in 1 nanosecond. This is a little surprising that it’s an exact number and it’s an integer. And the reason it’s an integer is because of the way Python does arithmetic. If all of the numbers here are integers, Python will truncate down to the integer. If we want a more accurate result, we should turn one of these numbers into a decimal number. So now we’ve changed the 1 to 1.0. Now we run it and we get 29.9792458, so almost 30cm, which is a better answer than 29 was..
For More Info : Visit Here : https://lightspeedreading.com/
No comments:
Post a Comment