In: Computer Science
Please write in python
Use modular design to write a program that asks the user to enter his or her weight and the name of a planet. The program then outputs how much the user would weigh on that planet. The following table gives the factor by which the weight must be multiplied for each planet.
PLANET |
CONVERSION FACTOR |
Mercury |
0.4155 |
Venus |
0.8975 |
Earth |
1.0000 |
Moon |
0.1660 |
Mars |
0.3507 |
Jupiter |
2.5374 |
Saturn |
1.0677 |
Uranus |
0.8947 |
Neptune |
1.1794 |
Pluto |
0.0899 |
The Program must meet the following requirements:
Short Summary:
**************Please upvote the answer and appreciate our time.************
Source Code:
# function to display the planets name
def userMenu():
print("Mercury \nVenus
\nEarth\nMoon\nMars\nJupiter\nSaturn\nUranus\nNeptune\nPluto\n")
# get user input
def userInput():
userMenu();
userWeight = float(input("Enter your weight: "));
planet = input("Enter name of the planet: ");
calculateWeight(userWeight,planet)
# method to calculate the Weight on the specific planet
def calculateWeight(weight,planetName):
# based on the planet display the weight
if planetName == "Mercury" :
print("Your weight on Mercury is
{:.2f}".format(weight*0.4155));
elif planetName== "Venus" :
print("Your weight on Venus is
{:.2f}".format(weight*0.8975));
elif planetName == "Earth":
print("Your weight on Earth is
{:.2f}".format(weight*1.0000));
elif(planetName== "Moon"):
print("Your weight on Moon is {:.2f}".format(weight*0.1660));
elif(planetName== "Mars"):
print("Your weight on Mars is {:.2f}".format(weight*0.3507));
elif(planetName== "Jupiter"):
print("Your weight on Jupiter is
{:.2f}".format(weight*2.5374));
elif(planetName== "Saturn"):
print("Your weight on Saturn is
{:.2f}".format(weight*1.0677));
elif(planetName== "Uranus"):
print("Your weight on Uranus is
{:.2f}".format(weight*0.8947));
elif(planetName== "Neptune"):
print("Your weight on Neptune is
{:.2f}".format(weight*1.1794));
elif(planetName== "Pluto"):
print("Your weight on Pluto is
{:.2f}".format(weight*0.0899));
else:
# if the planet enterd by the user is not a valid one display error
message
print("Planet Name entered is WRONG !!!. Please try again by giving
the FULL NAME of the PLANET");
# main method calls the user input method
def main():
userInput()
# starting point of the program
if __name__ == "__main__":
main()
Refer the following screenshots for code indentation:
Sample Run:
SAMPLE OUTPUT 2:
**************************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
**************************************************************************************