Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read the instructions carefully and follow them exactly : - The only collections you can use are strings, tuples, and lists. You may not use

Read the instructions carefully and follow them exactly:

- The only collections you can use are strings, tuples, and lists. You may not use any other collection (such as a set or dictionary) in this assignment. Using any of these in a solution to a question constitutes changing that question. Consequently, that question will not be graded.

- If you get help from the Internet or from another person, you must cite the section of code you borrowed and the source. Failure to do so will result in a grade of 0 for the whole assignment. You may only borrow no more than 15% of your code.

- Global variables are not allowed.

image text in transcribed

Problem One Enter the oil price in 'Qatar': 0.58 Write a function nonNegativeFloatValidation that takes as input a prompt and an errorMessage, which 'Qatar' is located in which continent? asi prompts you to enter a float based on a prompt. If the input is not a non-negative float it will display the Asi is not a valid continent, check your entry. errorMessage and prompts you for another input. If the input is valid, the function returns it. Hint: You 'Qatar' is located in which continent? Asia can re-use the function created in exercise 1 from week 7 to read and validate the oil prices. However, Enter the name for country 3: UK you need to adjust it slightly to accept float numbers. Enter the oil price in ' Uk:2.33 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 nonNegativeFloatValidation to read and check Problem Two 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 Now modify the code of the previous problem so that the readOilPrices function populates a 1D list list can be used to validate the continent. instead of a 2D list. The rest should be the same. Write a function listOilPrices that takes the 'prices' 2D list as input. This function prints the details of all The modified data structure: prices in a table format as shown in the sample run. ['Venezuela', 0.02, 'South America', 'Qatar', 0.58, 'Asia', 'UK', 2.33, 'Europe'] The readOilPrices should be called from the main program prompting the user to enter the oil price for Hint: you need to modify the function listOilPrices to print the oil prices from a 1D list instead of a 2D list. each country and then we call the listoilPrices to print a nicely formatted report as suggested in the sample run below. The sample run should be the same. 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions