write a program which asks the user to input the name of a planet with the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these computer network questions
-
Write a function total_equal_sides (ax, ay, bx, by, cx, cy, dx, dy): that consumes eight integers: ax and ay (the first vertex), bx and by (the second vertex), cx and cy (the third vertex), and dx...
-
Hypo 3: A small household staffing firm has recently realized it needs to change its marketing. The firm is owned by Anthony, a 60-year-old who has done this work for many years but has recently...
-
You are the support worker for a student with dyslexia. What resources might you be required to assemble or source? Give Six example.
-
In Exercises, find the limit. lim 5 x 0-x 813 X
-
Outline efficient syntheses of each of the following alkynes from acetylene and any necessary organic or inorganic reagents: (a) 1-Heptyne (b) 2-Heptyne (c) 3-Heptyne
-
Let X be the temperature in C at which a certain chemical reaction takes place, and let Y be the temperature in F (so Y = 1.8 X + 32). a. If the median of the X distribution is , show that 1.8 + 32...
-
The surface velocity of a river is measured at several locations \(x\) and can be reasonably represented by \[ V=V_{0}+\Delta V\left(1-e^{-a x} ight) \] where \(V_{0}, \Delta V\), and \(a\) are...
-
Pantene Paints has annual sales of $ 2,250,000 with variable expenses of 60 percent of sales and fixed expenses per month of $ 25,000. By how much must annual sales increase for Pantene Paints to...
-
What are the information parameters that support the roles played by Dummy file conversion in management? How can the absolute version of systems management be analyzed? What are the contributions of...
-
Forced conduction heat transfer from a flat plate (thermal boundary layer extends beyond the momentum boundary layer), show that the result analogous to Eq. 12.4-14 for > 1 is 2 3 1 37 1 315 Pr 140...
-
Find an international business and learn about its international strategy companies like Toyota and Starbucks will have a lot of information on their international strategy
-
If you decide not to pay an effective interest rate on a credit card above 15%, what is the maximum APR that you will be ready to pay a card for which the interest is compounded daily? Can someone...
-
Using the assignment instructions and the spreadsheet below, how should the formulas for cells D2:F2 be written? I know how to complete the data table but I am unable to figure out what formula...
-
Ray's GamePlace sells all the hottest gear and video games. On January 1, 20X7, Ray's had the following account balances: Accounts Receivable Less Allowance for Doubtful Accounts Net Accounts...
-
IWX Corporation is considering two possible investments and needs your help in determining which will be the better financial option. Perform the necessary calculations using Microsoft Excel so that...
-
Given the following is a probability distribution for returns on a security A, and a proxy for the market, M: State 1 2 3 4 Probability 10% 40% 40% 10% RA 12% 6% 1% -2% RM 15% 8% 4% -6% a. Calculate...
-
In a monopolistic competition environment, there are n identical firms. Each firm faces demand Q = 450,000 (-2(P-P)), where n is the number of firms, Q is quantity demanded from (and, in equilibrium,...
-
The slopes of the tangents at the points where the curve y = x2 - 4x intersects the X-axis is 1) 1 2) +2 3) +3 4) +4
-
Draw a picture of an initially empty data structure, as described in the previous exercise, after adding the numbers 2, 8, 4, and 6, in this order.
-
Suppose you are writing a program that asks the user to give a yes-or-no response. Assume that the program reads the users response into the Stringvariableresponse. a. If response is yes or y, set...
-
Do Programming Project 17 from Chapter 4, the Edoc calculator, except write a method that takes the number of candy, Edoc, and Margorp as input parameters and returns the amount of experience that...
-
An important dimensionless parameter concerned with very high-speed flow is the Mach number, defined as \(V / c\), where \(V\) is the speed of the object such as an airplane or projectile, and \(c\)...
-
Often the assumption is made that the flow of a certain fluid can be considered as incompressible flow if the density of the fluid changes by less than \(2 \%\). If air is flowing through a tube such...
-
The "power available in the wind" of velocity \(V\) through an area \(A\) is \[ \dot{W}=\frac{1}{2} ho A V^{3} \] where \(ho\) is the air density \(\left(0.075 \mathrm{lbm} / \mathrm{ft}^{3} ight)\)....
Study smarter with the SolutionInn App