Python - How should I keep the key,value pairs in order when I print all of them?

I am brand new to coding and the project I am working on converts the user's weight on Earth into their weight on different planets of the solar system. I would like some suggestions on how I can make the output maintain the order in which I entered the elements into the dictionary.

Forgive my ignorance as I am trying to teach myself and I have just started with Python. Any guidance would be greatly appreciated.

earthWeight = float(input("How much do you weigh (in lbs)?: "))

#user's weight is calculated based on the planet.

sunWeight = earthWeight * 27.01

mercuryWeight = earthWeight * .38

venusWeight = earthWeight * .91

moonWeight = earthWeight * .166

marsWeight = earthWeight * .38

jupiterWeight = earthWeight * 2.34

saturnWeight = earthWeight * 1.06

uranusWeight = earthWeight * .92

neptuneWeight = earthWeight * 1.19

plutoWeight = earthWeight * .06

celestialWeight = {
    'Weight on Sun: ' : sunWeight, 
    'Weight on Mercury: ' : mercuryWeight,
    'Weight on Venus: ' : venusWeight,
    'Weight on Moon: ' : moonWeight,
    'Weight on Mars: ' : marsWeight,
    'Weight on Jupiter: ' : jupiterWeight,
    'Weight on Saturn: ' : saturnWeight,
    'Weight on Uranus: ' : uranusWeight,
    'Weight on Neptune: ' : neptuneWeight,
    'Weight on Pluto: ' : plutoWeight}


for key, value in sorted(list(celestialWeight.items())):
    print(key, value)


from Recent Questions - Stack Overflow https://ift.tt/3wSfYk1
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)