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:
![Write a function nonNegativeFloatValidation that takes as input a prompt and an errorMessage, which prompts](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/09/651527d6c6b58_1695885262227.jpg)
![Sample Run Enter the number of countries: three The number of countries must be a positive number greater](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/09/651527ed39d46_1695885286120.jpg)
!['Qatar' is located in which continent? asi Asi is not a valid continent, check your entry. 'Qatar' is located](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/09/6515280842e85_1695885313152.jpg)
![Problem Two Now modify the code of the previous problem so that the readOil Prices function populates a 1D](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2023/09/6515282072095_1695885337342.jpg)
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....
-
What is a Dutch auction?
-
On September 1, 2024, Speedy Lube signed a 30-year, $1,080,000 mortgage note payable to Jonstown Bank and Trust in conjunction with the purchase of a building and land. The mortgage note calls for...
-
2 How could levels of reconciliation and integration among the different racial groups in South Africa be increased a) in the short term b) in the long term?
-
How are operating expenses (not included in cost of goods sold) handled under the installment-sales method of accounting? What is the justification for such treatment?
-
8. What is the consolidated balance for dividend declared at December 31, 2020? Your answer: 9. What is the net income attributable to noncontrolling interests of Gardena at December 31, 2020? Your...
-
1. If you were to manage this project: (a) How would you have written up the project scope statement? Include the following elements in the scope statement: objectives, deliverables, and constraints....
-
How does diversification of income streams affect employees of a company
-
(a) Draw a simplified ray diagram showing the three principal rays for an object located inside the focal length of a converging lens, closer to the lens than to the focal point. (b) Is the image...
-
Power efficiency has become very important for modern processors, particularly for embedded systems. Create a version of gcc for two architectures that you have access to, such as x86, RISC-V,...
-
There is a movement toward wireless mobile computing using thin-client technology. Go to the Web and visit some of the ma jor computer vendors that are producing thin-client products such as handheld...
-
Draw a B-tree of order 4 and height 3 containing the fewest elements. Show an example of a split that would be applied by inserting the fewest number of elements.
-
Repeat Example 10-4, except calculate the diameter at the bottom of the column. Example 10-4 A distillation column is separating n-hexane from n-heptane using 1-in. ceramic Intalox saddles. The...
-
Question 1 S points Save Answer If 1) the expected return for XYZ stock is 9.5 percent; 2) the dividend is expected to be $4.38 in one year, 54.62 in two years. $0 in three years, and $3.81 in four...
-
The purpose of this case is to come up with a contingency plan[s] in order to sustain the program Move With Me, a program that serves thousands of community members throughout Lower Manhattan. The...
-
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...
-
52. A city receives a copy of its original charter from the year 1799 as a gift from a citizen. The docu ment will be put under glass and displayed in the city hall for all to see. The fair value is...
-
50. A city has a solid waste landfill that was filled 12 percent in Year 1 and 26 percent in Year 2. Dur ing those periods, the government expected that total closure costs would be $2 million. As a...
-
48. The City of Wolfe bought a $20,000 machine with a five-year life and no salvage value for its school system. It was capitalized but no other entries were ever made. The machine was monitored...
![Mobile App Logo](https://dsd5zvtm8ll6.cloudfront.net/includes/images/mobile/finalLogo.png)
Study smarter with the SolutionInn App