Your task is to write a program which asks the user to input the name of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
PLANET DENSITIES mercury 5429 venus 5243 earth 5514 mars 3933 jupiter 1326 ... View the full answer
Related Book For
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis
Posted Date:
Students also viewed these programming questions
-
Consider a special version of 3-SAT that requires that each variable has exactly 3 occurrences, but allows each clause to have either 2 or 3 literals. Let's call this problem 2,3-SAT3. Here is an...
-
Genos Restaurant has a dress policy that requires female servers to wear a uniform provided by the restaurant, but male servers are simply told to wear black shirts and blank slacks. The uniforms...
-
For this exercise you need to go through the various information challenges and identify the most suitable market research approach it should use to help gather information. Henrys Hometown Pizza has...
-
Which of the following statements about close buyer-seller relationships in business markets is FALSE? Long-term commitments on larger order quantities often cause the supplier to raise its selling...
-
In which ways does Mary Kay instill a cultural value system based on achievement and a deep sense of personal worth?
-
What volume of oxygen gas, in liters, at 30 C and 0.993 atm reacts with excess hydrogen to produce 4.22 g water?
-
Write the following numbers in scientific notation form: 1. -38300 2. 0.0045 3. 1
-
Duncan Company combines its operating expenses for budget purposes in a selling and administrative expense budget. For the first 6 months of 2012, the following data are available. 1. Sales: 20,000...
-
THANK FINANCE!. 2. (40) Consider a special type of lookback option whose payoff at maturity is given by the difference between the maximum and minimum stock prices attained over the life of the...
-
A political scientist developed a questionnaire to determine political tolerance scores (Y) for a random sample of faculty members at her university. She wanted to compare mean scores adjusted for...
-
in a study on the lifestyle of single adults, researchers surveyed a random sample of 963 single adults and asked whether or not they owned pets. The population of interest is A. The group of 963...
-
A survey by the Center for State and Local Government Excellence conducted among members of the International Public Management Association for Human Resources and the National Association of State...
-
The following list includes common auditing procedures. For each procedure: (1) describe the procedure; (2) identify the primary financial statement assertion, such as existence, for which the...
-
When auditing a computer accounting system, the independent auditor should understand how the use of computers affects the various characteristics of internal control. The indepen dent auditor should...
-
Refer to Question 11-44 in Chapter 11. For each weakness noted in the question, indicate a general control or an application control that would overcome that weakness and how that control could be...
-
What factors must auditors consider when making materiality decisions?
-
3. Describe the Discounted Cash Flow Method. How is this value determined, and what are the assumptions/limitations?
-
Draw the major product for each of the following reactions: (a) (b) (c) 1) 9-BBN 2) H2O2, NaOH 1) Disiamylborane 2) H20, NaOH
-
You use this statement to throw an exception manually. a. Try b. Generate c. Throw d. System.exit(0)
-
True or False: If the toUpperCase methods argument is already uppercase, it is returned as is, with no changes.
-
Assume x is an int variable, and rand references a Random object. What does the following statement do? x = rand.nextInt();
-
The trial balance of Jeremina plc as at 31 March 2002 is as follows: (i) Stock of finished goods on 31 March 2002 163,000. (ii) Motor expenses and depreciation on motors to be apportioned:...
-
You are Br erired: with the following information relating to Plott plc for the year to 31 March 2011: Additional information: 1. The above information has been obtained after the compilation of the...
-
The following information has been extracted from the books of Quire plc as at 30 September 2011. The following additional information is to be taken into account: 1. Stocks at 30 September 2011 were...
Study smarter with the SolutionInn App