Question: Your task is to write a program which asks the user to input the name of a planet with the attribute name, and the program

Your task is to write a program which asks the user to input the name of a planet with the attribute name, and the program will show the value for this attribute

The density and gravity of each planet are:

Planet Density (kg/m^3) Gravity (m/s^2)
mercury 5429 3.7
venus 5243 8.9
earth 5514 9.8
mars 3934 3.7
jupiter 1326 23.1
saturn 687 9.0
uranus 1270 8.7
neptune 1638 11.0

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. The dictionary must consist of planet data. The attribute in each planet must be represented in disctionary as well. Next, ask the user to input a planet name. If the planet name is in the dictionary, the program will ask the attribute name. If the attribute is in the planet's dictionary, the value of this attribute will be displayed. If the planet is recognised but the attribute is not recognised, display the message "Unrecognised Attribute". 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.

Criteria

During marking we will check that your program:

Defines a dictionary constant containing planet names with density and gravity attributes and use this in your code. Give the constant an appropriate name which follows Python conventions. (6 marks)

Defines a dictionary constant containing measurement units and use this in your code. Give the constant an appropriate name which follows Python conventions. (3 marks)

Accepts the planet name from the user with an appropriate input statement. (2 marks)

Ignores the capitalisation of user input. (2 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)

Checks whether the input planet's attribute 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 attributes name. (3 marks)

Gets and displays the planet density using the dictionary constant. (3 marks)

Executes as expected for example and other inputs. (3 marks)

Example Runs

Run 1

Enter the name of a planet: saturn Enter the attribute name: gravity This planet has a gravity of 9.0 m/s^2

Run 2

Enter the name of a planet: EaRTh Enter the attribute name: DEnSIty This planet has a density of 5514 km/m^3

Run 3

Enter the name of a planet: Jupiter Enter the attribute name: ring Unrecognised Attribute

Run 4

Enter the name of a planet: naboo Unrecognised Planet

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!