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....
-
Astronomers often use large mirrors in their telescopes to gather as much light as possible from faint distant objects. Should the mirror in their telescopes be concave or convex? Explain.
-
Answer the following questions using the information provided in this chapter. a. As a percentage of employed workers, what is the size of the flows into and out of employment (i.e., hires and...
-
For the first quarter of 2005, Philips Sales Corporation has budgeted sales of \($390,000\) and budgeted cost of goods sold of \($280,000.\) In addition, the budget for the first quarter of 2005...
-
A used-car broker needs to transport his inventory of cars from locations 1 and 2 in Figure to used-car auctions being held at locations 4 and 5. The costs of transporting cars along each of the...
-
Book Print erences 1. Salary of the company president-$32,300, 2. Salary of the vice president of manufacturing-$16,400. 3. Salary of the chief financial officer-$18,400. 4. Salary of the vice...
-
Fill-in the following using the data below. At Haddon, Inc., the office workers are employed for a 40-hour workweek. All workers, except King and Manera, are entitled to overtime pay for all hours...
-
Kari Corp., a manufacturing company, was organized on January 2, Year 1. Its Year 1 federal taxable income was $400,000 and its federal income tax was $100,000. What is the maximum amount of...
-
Assuming Jay and JoAnn have this same business that they run as a regular corporation, prepare their joint Federal income tax return for 2 0 1 6 . They each received a W - 2 from the business which...
-
(a) What is the coefficient of kinetic friction between the crate and the floor? (Enter your answer to at least three decimal places.) (b) If the 390-N force is instead pulling the block at an angle...
-
On April 1 , 2 0 2 2 , PT Megapro leased a heavy equipment to PT Wahana. The fair value of the machine is Rp 3 6 5 , 7 6 0 , 0 0 0 and is estimated to have a residual value of Rp 2 5 , 0 0 0 , 0 0 0...
-
On November 1 , 2 0 X 9 , Jacquie Co . exchanged a blue truck ( with an original cost of $ 5 0 , 0 0 0 and a book value of $ 2 0 , 0 0 0 ) for a red truck from Wother Co . In addition to the blue...
-
A 9-volt battery is attached in series to a 200 Ohm resistor. A) Calculate the current flowing through the circuit. B) if a second 200 Ohm resistor is added to the circuit, will the current INCREASE...
-
You feel confident in your investment knowledge and would like to invest into Malaysian stock market. Given the above scenario, you are required to: a) What do you think about the movement of FBMKLCI...
-
Catherine (aged 42) and Johnson (aged 45) have been married for 12 years. Johnson is a project manager of an event company at a monthly salary of $55,000 with an additional one-month salary of...
-
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...
-
What are pro formas?
-
The following information is taken from the accounting records of Donald Company: Average receivables \(\$ 700,000\) Cost of goods sold \(.2,900,000\) Sales \(8,000,000\) Average inventory...
-
How does a forensic accountant analyze inventories and receivables?
Study smarter with the SolutionInn App