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...
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!!...
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.”
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a complete Python program that asks the user for a line of text (not just...
Write a complete Python program that asks the user for a line of text (not just a single word), and then tells the user whether the string is a palindrome (same forward and backward) if you ignore case and non-alphabetic characters. The following methods and functions may be useful: str.upper(), str.isalpha() -> bool, reversed(str) -> sequence, str.find(str) -> int, str.replace(str, str), str.center(int). Unless otherwise specified, they all return a string.
CODE IN PYTHON 1. Write a program that asks the user for the number of slices...
CODE IN PYTHON 1. Write a program that asks the user for the number of slices of pizza they want to order and displays the total number of dollar bills they owe given pizza costs 3 dollars a slice.  Note: You may print the value an integer value. 2. Assume that y, a and b have already been defined, display the value of x: x =   ya+b    3. The variable start_tees refers to the number of UD T-shirts at the start...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT