Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your task is to write a program which asks the user to input the name of a planet. The program should then display the

  

Your task is to write a program which asks the user to input the name of a planet. The program should then display the density of that planet. The density of each planet is: Planet Density mercury 5429 venus 5243 earth 5514 mars 3934 jupiter 1326 saturn 687 uranus 1270 neptune 1638 Source: https://nssdc.gsfc.nasa.gov/planetary/factsheet/ In your code you shall define a dictionary constant containing the data in the above table, using the appropriate data types for keys and values. Next, ask the user to input a planet name. If the planet name is in the dictionary, display the density of the planet. Otherwise, display the message "Unrecognised planet". To be more user-friendly, you must also ignore the capitalisation of the input name when checking it (i.e. "mercury", "MERCURY", and "Mercury" are all accepted by the program). Hint: Ensure that planet names in your dictionary are all in lowercase, then use the appropriate string method to convert the user input to lowercase also. r 1. r Criteria During marking we will check that your program: Defines a dictionary constant containing planet names and densities and use this in your code. Give the constant an appropriate name which follows Python conventions. (4 marks) Accepts the planet name from the user with an appropriate input statement. (2 marks) Ignores the capitalisation of user input. (4 marks) Checks whether the input planet is not in the dictionary and print an appropriate output message. You must not write code which explicitly compares the user input with each individual planet name. (3 marks) Gets and displays the planet density using the dictionary constant. (4 marks) Executes as expected for example and other inputs. (3 marks) Example Runs Run 1 Enter the name of a planet: mercury That planet has a density of 5429 kg/m 3 Run 2 Enter the name of a planet: EaRtH That planet has a density of 5514 kg/m 3 Run 3 Enter the name of a planet: naboo Unrecognised planet Your code should execute as closely as possible to the example runs above. To check for correctness, ensure that your program gives the same outputs as in the examples, as well as trying it with other inputs.

Step by Step Solution

3.33 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

PLANET DENSITIES mercury 5429 venus 5243 earth 5514 mars 3933 jupiter 1326 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Starting Out With Java From Control Structures Through Data Structures

Authors: Tony Gaddis

6th Edition

0133957055, 978-0133957051

More Books

Students also viewed these Programming questions

Question

How did Spinoza and Descartes challenge beliefs in witchcraft?

Answered: 1 week ago