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...
-
The 10-kg block A and the 4-kg block B are both at a height h = 0.5 m above the ground when the system is released from rest. After A hits the ground without rebound it is observed that B reaches a...
-
A statement of cash flows for Friendly Markets, Inc., for 20X1 appears below. Operations (1) Net income $ 1,161,442 Adjustments for noncash transactions: (2) Depreciation and amortization 496,106 (3)...
-
We live in a global economy, and many different external activities have an impact on the business. On what basis would we narrow the scope of this book to de-emphasize tax law, currency exchange,...
-
Foghorn Leghorn is considering the replacement of an old egg-sorting machine used with his Foggy's Farm Fresh Eggs business. The old ,egg machine is not quite running eggs actly the way it was...
-
What would be your annualized Discount Rate (in %) and your annualized Investment Return (%) on the purchase of a 91 day U.S. T. Bill for $4,975.00 that has a Par Value of $5,000.00?
-
Ellipses Corp is a small business that operates in Herndon, VA. The company is located at10 Period Lane, Herndon, VA 20170. Its federal Employer Identification Number is 77-7777777, and its...
-
The land of Nod has a Queen named Virginia who took over the throne after her late mother Carolina passed away from natural causes. Virginia is meaner than her mother. She makes people salute her in...
-
Lakehead Capital is looking to raise $5.5 million for a new venture. Lakehead Capital can borrow money from a bank at a 6.8% interest each year or raise money by issuing equity to the market. After...
-
A customer borrowed $1000, and must make 3 payments of $500 each to repay the loan. How much interest will they have paid on top of the amount they borrowed? Type your answer:
-
The following information applies to Acorn Construction Company (ACC): Year 2 Year 1 Net sales $ 1,180,000 $ 750,000 Income before interest and taxes 165,000 99,000 Net income 74,000 59,500 Interest...
-
Does the company have any other incomes or expenses outside its normal operating bussiness?
-
Derive the number of futures contracts required to hedge a position in a well diversified portfolio of stocks. Briefly explain.
-
21. Why neurons and some other specialized cells divide infrequently? They have been shunted into GO They can no longer bind Cdk to cyclin They no longer have active nuclei They no longer carry...
-
What is removed during each of the three stages of wastewater treatment: primary, secondary, and tertiary? During which state would you expect items to be recovered that were accidentally flushed,...
-
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();
-
For the data set below, use a partial \(F\)-test to determine whether the variables \(x_{4}\) and \(x_{5}\) do not significantly help to predict the response variable, \(y\). Use the \(\alpha=0.10\)...
-
Suppose we record the gender of the 15 students enrolled in an introductory statistics course as they enter the classroom. The males are denoted by a blue M and the females are denoted by a red...
-
A nutritionist wants to develop a model that describes the relation between the calories, total fat content, protein, sugar, and carbohydrates in cheeseburgers at fast-food restaurants. She obtains...
Study smarter with the SolutionInn App