Write a function nonNegativeFloatValidation that takes as input a prompt and an errorMessage, which prompts you...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function nonNegativeFloatValidation that takes as input a prompt and an errorMessage, which prompts you to enter a float based on a prompt. If the input is not a non-negative float it will display the errorMessage and prompts you for another input. If the input is valid, the function returns it. Hint: You can re-use the function created in exercise 1 from week 7 to read and validate the oil prices. However, you need to adjust it slightly to accept float numbers. Write the function readOilPrices that takes an empty 2D list 'prices' representing the oil prices, and a positive integer noOfCountries to represent the total number of countries. The function asks the user which country he would like to add, then the price and continent repeatedly. The function should populate a 2D list in the following format: Sample data structure: [['Venezuela', 0.02, 'South America'], ['Qatar', 0.58, 'Asia']], ['UK', 2.33, 'Europe']] You need to validate the input as well. You can use the nonNegative FloatValidation to read and check that the user enters a non-negative price each time. You need to define a list of continents (Asia, Africa, Europe, North America, South America, South America, Australia, and Antarctica) in this function. This list can be used to validate the continent. Write a function listOilPrices that takes the 'prices' 2D list as input. This function prints the details of all prices in a table format as shown in the sample run. The readOil Prices should be called from the main program prompting the user to enter the oil price for each country and then we call the listOilPrices to print a nicely formatted report as suggested in the sample run below. Sample Run Enter the number of countries: three The number of countries must be a positive number greater than zero. Enter the number of countries: 3 Enter the name for country 1: venezuela Enter the oil price in 'Venezuela': twelve Invalid entry, the price must be a float number greater than zero. Enter the oil price in 'Venezuela": -1 Invalid entry, the price must be a float number greater than zero. Enter the oil price in Venezuela': 0.02 'Venezuela' is located in which continent? south america Enter the name for country 2: Qatar Enter the oil price in 'Qatar': 0.58 'Qatar' is located in which continent? asi Asi is not a valid continent, check your entry. 'Qatar' is located in which continent? asia Enter the name for country 3: UK Enter the oil price in 'Uk': 2.33 'Uk' is located in which continent? Europe Country Venezuela Qatar UK Oil Price 0.02 0.58 2.33 Continent South America Asia Europe Problem Two Now modify the code of the previous problem so that the readOil Prices function populates a 1D list instead of a 2D list. The rest should be the same. The modified data structure: ['Venezuela', 0.02, 'South America', 'Qatar', 0.58, 'Asia', 'UK', 2.33, 'Europe'] Hint: you need to modify the function listOilPrices to print the oil prices from a ID list instead of a 2D list. The sample run should be the same. Write a function nonNegativeFloatValidation that takes as input a prompt and an errorMessage, which prompts you to enter a float based on a prompt. If the input is not a non-negative float it will display the errorMessage and prompts you for another input. If the input is valid, the function returns it. Hint: You can re-use the function created in exercise 1 from week 7 to read and validate the oil prices. However, you need to adjust it slightly to accept float numbers. Write the function readOilPrices that takes an empty 2D list 'prices' representing the oil prices, and a positive integer noOfCountries to represent the total number of countries. The function asks the user which country he would like to add, then the price and continent repeatedly. The function should populate a 2D list in the following format: Sample data structure: [['Venezuela', 0.02, 'South America'], ['Qatar', 0.58, 'Asia']], ['UK', 2.33, 'Europe']] You need to validate the input as well. You can use the nonNegative FloatValidation to read and check that the user enters a non-negative price each time. You need to define a list of continents (Asia, Africa, Europe, North America, South America, South America, Australia, and Antarctica) in this function. This list can be used to validate the continent. Write a function listOilPrices that takes the 'prices' 2D list as input. This function prints the details of all prices in a table format as shown in the sample run. The readOil Prices should be called from the main program prompting the user to enter the oil price for each country and then we call the listOilPrices to print a nicely formatted report as suggested in the sample run below. Sample Run Enter the number of countries: three The number of countries must be a positive number greater than zero. Enter the number of countries: 3 Enter the name for country 1: venezuela Enter the oil price in 'Venezuela': twelve Invalid entry, the price must be a float number greater than zero. Enter the oil price in 'Venezuela": -1 Invalid entry, the price must be a float number greater than zero. Enter the oil price in Venezuela': 0.02 'Venezuela' is located in which continent? south america Enter the name for country 2: Qatar Enter the oil price in 'Qatar': 0.58 'Qatar' is located in which continent? asi Asi is not a valid continent, check your entry. 'Qatar' is located in which continent? asia Enter the name for country 3: UK Enter the oil price in 'Uk': 2.33 'Uk' is located in which continent? Europe Country Venezuela Qatar UK Oil Price 0.02 0.58 2.33 Continent South America Asia Europe Problem Two Now modify the code of the previous problem so that the readOil Prices function populates a 1D list instead of a 2D list. The rest should be the same. The modified data structure: ['Venezuela', 0.02, 'South America', 'Qatar', 0.58, 'Asia', 'UK', 2.33, 'Europe'] Hint: you need to modify the function listOilPrices to print the oil prices from a ID list instead of a 2D list. The sample run should be the same.
Expert Answer:
Answer rating: 100% (QA)
Heres the Python code for the first part of your problem which includes the functions nonNegativeFloatValidation readOilPrices and listOilPrices code Function to validate nonnegative float input def n... View the full 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 programming questions
-
What are some techniques that can be used to forecast the supply and demand of labor in an organization. Explain
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Read the case study "Southwest Airlines," found in Part 2 of your textbook. Review the "Guide to Case Analysis" found on pp. CA1 - CA11 of your textbook. (This guide follows the last case in the...
-
The ordinary share capital of W Ltd (which is a trading company) is owned 30% by X Ltd, 25% by Y Ltd and 45% by Z Ltd. All of these companies are UK resident and they prepare accounts to 31 March....
-
Let G = (V, E) be an undirected, connected graph with weight function w : E R, and suppose that |E| |V| and all edge weights are distinct. A second-best minimum spanning tree is defined as follows....
-
A major reason that the finance function has taken on a more strategic role is because a Finance is especially qualified in trending and projections b Finance is responsible for funding the future c...
-
Consider the simple linear regression model fit to the tank pressure and volume data in Problem 2.16. Problem 2.16 Carroll and Spiegelman ("The Effects of Ignoring Small Measurement Errors in...
-
SWAT Team Surplus began July with 66 tents that cost $23 each. During the month, SWAT Team Surplus made the following purchases at cost: Jul 4 105 tents @ $25 = $2,625 19 157 tents @ $27 = 4,239 25...
-
Congratulations, on being appointed as the director of the North Carolina Open Singles Badminton Championships. You have been researching probable revenues and costs so that you can make a budget....
-
ZIM Inc. (ZIM) is a high-technology company that develops, designs, and manufactures telecommunications equipment. ZIM was founded in Year 5 by Dr. Alex Zimmer, the former assistant head of research...
-
Suppose you are the head of the Central Bank in Candiland. The current inflation rate is 4%. As the Central Bank, you want to achieve a target inflation rate of 2.5% within a year. Candiland has a...
-
The action of walking away from a potential sale is often considered a high-risk negotiations strategy. What three actions did Lana employ before she walked away from the sale?
-
Watson Heater Company sells portable heaters and related equipment. The business uses a perpetual inventory system, and the cost of its inventory at the beginning of November was \(\$ 2600\). Its...
-
Many long-term loans are payable over a period of time. For example, when a business takes out a mortgage to finance a building, it pays off a fraction of that mortgage every month. Required: What...
-
While reviewing the Taber Business' income statement for the year, you find that it had sales of \(\$ 81500\), cost of goods sold of \(\$ 50000\) and wages expense of \(\$ 30200\). A review of its...
-
ABC Optical began 20X1 with accounts receivable of \(\$ 44800\) and inventory of \(\$ 56000\). During \(20 \mathrm{X} 1\) the business made total net sales of \(\$ 840000\), of which 70 per cent were...
-
QUESTION 23 Which of the following is true of running a Spark application on Hadoop YARN? O A. Irrespective of the mode, the driver is launched the client process that submitted the job OB. Running...
-
Select the correct answer for each of the following questions. 1. On December 31, 20X3, Saxe Corporation was merged into Poe Corporation. In the business combination, Poe issued 200,000 shares of its...
-
Create a program that tests the class Android described in the previous exercise. Previous exercise. Create a class Android whose objects have unique data. The class has the following attributes:...
-
Rewrite the Dog class given in Listing 5.1 by utilizing the information and encapsulation principles described in Section 5.2. The new version should include accessor and mutator methods. Also define...
-
The class StringLinkedListWithIterator (Listing 12.9) is its own iterator, but it does not quite implement the Java Iterator interface. Redefine the class StringLinkedListWithIterator so that it...
-
An atom loses an electron to another atom. Is this an example of a physical or chemical change? (a) chemical change involving the formation of ions (b) physical change involving the formation of ions...
-
Why are ores so valuable? (a) They are sources of naturally occurring gold. (b) Metals can be efficiently extracted from them. (c) They tend to occur in scenic mountainous regions. (d) They hold many...
-
Aluminum ions carry a 3+ charge, and chloride ions carry a 1- charge. What is the chemical formula for the ionic compound aluminum chloride? (a) Al 3 Cl (b) AlCl 3 (c) Al 3 Cl 3 (d) AlCl
Study smarter with the SolutionInn App