-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import math | ||
|
||
def main(): | ||
MERCURY_GRAVITY = (37.6 / 100) | ||
VENUS_GRAVITY = (88.9 / 100) | ||
MARS_GRAVITY = (37.8 / 100) | ||
JUPITER_GRAVITY = (236 / 100) | ||
SATURN_GRAVITY = (108.1 / 100) | ||
URANUS_GRAVITY = (81.5 / 100) | ||
NEPTUNE_GRAVITY = (114 / 100) | ||
|
||
earthWeight = float(input("Enter the object weight: ")) | ||
planetName = input("Enter a planet name: ") | ||
|
||
match planetName: | ||
case "Mercury": | ||
planetWeight = float(earthWeight) * MERCURY_GRAVITY | ||
|
||
case "Venus": | ||
planetWeight = float(earthWeight) * VENUS_GRAVITY | ||
|
||
case "Mars": | ||
planetWeight = float(earthWeight) * MARS_GRAVITY | ||
|
||
case "Jupiter": | ||
planetWeight = float(earthWeight) * JUPITER_GRAVITY | ||
|
||
case "Saturn": | ||
planetWeight = float(earthWeight) * SATURN_GRAVITY | ||
|
||
case "Uranus": | ||
planetWeight = float(earthWeight) * URANUS_GRAVITY | ||
|
||
case "Neptune": | ||
planetWeight = float(earthWeight) * NEPTUNE_GRAVITY | ||
|
||
case "Earth": | ||
planetWeight = float(earthWeight) | ||
|
||
case other: | ||
planetWeight = -1.0 # Why put a negative value here? | ||
|
||
print("The name of the planet: " + planetName + " with weight: " + str(planetWeight)) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
planet_dict = [ | ||
{"mercury": 0.376}, | ||
{"venus": 0.889}, | ||
{"mars": 0.378}, | ||
{"jupiter": 2.36}, | ||
{"saturn": 1.081}, | ||
{"uranus": 0.815}, | ||
{"neptune": 1.14} | ||
] | ||
|
||
def calculate_weight(target_planet, earth_weight): | ||
# TODO: Check the earth weight, make sure >= 0 and numbers only | ||
# TODO: Check that the target planet name is listed in the dictionary, otherwise return an error | ||
|
||
planet_name = target_planet.lower() | ||
planet_constant = -1.0 | ||
for i in range( len(planet_dict) ): | ||
for name, gravity in planet_dict[i].items(): | ||
if (planet_name == name): | ||
planet_constant = gravity | ||
else: | ||
return -1.0 | ||
planet_weight = planet_constant * earth_weight | ||
|
||
return planet_weight | ||
|
||
def main(): | ||
earth_weight = float(input("Enter the object weight: ")) | ||
planet_name = input("Enter a planet name: ") | ||
|
||
planet_weight = calculate_weight(planet_name, earth_weight) | ||
|
||
print("The name of the planet: " + planet_name + " with weight: " + str(planet_weight)) | ||
|
||
if __name__ == '__main__': | ||
main() |