Question

In: Computer Science

Please write in python Use modular design to write a program that asks the user to...

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:

  1. The program must have a menu
  2. The program should output an error message if the user doesn’t type a correct planet name. The prompt and the error message should make it clear to the user how a planet name must be entered.
  3. The output should be labeled clearly and formatted neatly.
  4. The output must be display with 2 decimal points.
  5. Use modular design
  6. Use proper documentation

Solutions

Expert Solution

Short Summary:

  • Provided the source code and sample output as per the requirements.

**************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!!!

**************************************************************************************


Related Solutions

Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
Please write in Python code please: Write a program that asks the user to enter 5...
Please write in Python code please: Write a program that asks the user to enter 5 test scores between 0 and 100. The program should display a letter grade for each score and the average test score. You will need to write the following functions, including main: calc_average – The function should accept a list of 5 test scores as an input argument, and return the average of the scores determine_grade – The function should accept a test score as...
Design a modular program which asks the user to enter a list of numbers. The numbers...
Design a modular program which asks the user to enter a list of numbers. The numbers must be stored in an array. The program then finds the index of the first occurrence of the smallest element in the array and the last occurrence of the largest element in the array. The program displays the position and value of each of these items.
Q2. Design a Pearson modular program that asks the user to enter the monthly costs for...
Q2. Design a Pearson modular program that asks the user to enter the monthly costs for each of the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, and maintenance (create a module for each expense). The program should then display the total monthly cost of these expenses, and the total annual cost of these expenses in the main Module. Use Pass arguments By Reference method to design your modules. Submit your pseudocode with comments at...
Python: Write a program that asks the user for the name of a file. The program...
Python: Write a program that asks the user for the name of a file. The program should display the contents of the file line by line.
Number Analysis Program (Specific Design Specifications) Design a Python program that asks the user to enter...
Number Analysis Program (Specific Design Specifications) Design a Python program that asks the user to enter a series of 20 numbers. The program should store the numbers in a list then display the following data: The lowest number in the list The highest number in the list The total of the numbers in the list The average of the numbers in the list This python program must include the following functions. Your program must use the exact names, parameter lists,...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
In PYTHON: Write a program that asks for a password from a user and checks if...
In PYTHON: Write a program that asks for a password from a user and checks if it satisfies the conditions: Contains at least one lowercase letter (a-z). Contains at least one uppercase letter (A-Z). Contains at least one digit (0-9). Minimum length 6 characters. Contains no spaces. If the password is valid, then the program prints “password accepted”. Otherwise, it keeps asking for more passwords from the user until a valid password is obtained. Hint: You might like to check...
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
Python English algorithm explanation Write a program that asks the user for the name of a...
Python English algorithm explanation Write a program that asks the user for the name of a file in the current directory. Then, open the file and process the content of the file. 1)If the file contains words that appear more than once, print “We found duplicates.” 2)If the file does not contain duplicate words, print “There are no duplicates.”
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT