Question: Write a function nonNegativeFloatValidation that takes as input a prompt and an errorMessage, which prompts you to enter a float based on a prompt.

Write a function nonNegativeFloatValidation that takes as input a prompt and an errorMessage, which prompts Sample Run Enter the number of countries: three The number of countries must be a positive number greater 'Qatar' is located in which continent? asi Asi is not a valid continent, check your entry. 'Qatar' is located Problem Two Now modify the code of the previous problem so that the readOil Prices function populates a 1D

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.

Step by Step Solution

3.50 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

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 full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!