Question: write a program which asks the user to input the name of a planet with the attribute name, and the program will show the
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/m3) Gravity (m/s2) mry 5429 17 virus 5243 8.9 carth 5514 9.8 3934 ju 1326 satum 687 uranus 12/0 neptune 1638 23.1 9.0 87 11.0 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 (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 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. Your Solution [ ] # Write your solution here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
