0

For my 'intro to coding class', our assignment is to calculate how far (meters) light travels in one year. I currently have completed that, however I am having trouble converting my large answer into an exponent form. we are using the newest form of python on a website called MindTap. How would I go about converting my answer into exponent form?

Here is my code for the assignment

secinyear = float(365*24*60**2)
rate = float(3*10**8)
cal = (secinyear * rate)

print("Light travels ", cal, "meters in a year.")

cal come out to be 9460800000000000.0. I wish to turn this into a proper exponent form such as 9.4608 x 10^15.

AEM1059
  • 3
  • 1

2 Answers2

2

Does something like this meet your needs?

value = 2857434.93485
print("{:.2e}".format(value))

The result is 2.86e+06

Matthew Gaiser
  • 4,558
  • 1
  • 18
  • 35
0

Try the string formatting method in python:

print(f"Light travels {cal:.2e} meters in a year.")

Output:

Light travels 9.46e+15 meters in a year.
Toukenize
  • 1,390
  • 1
  • 7
  • 11