Question

List Python

A car park management system uses a list to represent which spaces in a car park are currently occupied and which are currently unoccupied. An empty space is represented by a 0 and a full space by a 1.
Then the state of the car park would be represented by the following list:
[1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0]
The designers of the car park management system require a program that will accept a list such as the one above (although of course the length will not always be 11) and calculate what percentage of the spaces are currently occupied, rounded to the nearest percent.
In the example above 7 spaces are occupied and there are 11 altogether, so the percentage occupied is: (7 / 11) x 100 = 63.63… = 64% to the nearest whole number.

i.What are the admissible inputs of the problem?
ii.What is the output of this problem?
iii.Write three tests for this problem. The inputs should be different from the example given in the scenario description above. At least one of your tests must be a borderline case. Present the tests in a table, with a column for each input and output, and an extra column with a brief explanation of why you selected each test
iv.Decompose the problem into sub-problems. Use the > notation and state in brackets the type of the problem and of each sub-problem
v. Choose the patterns for the subproblem types you identified, instantiate the patterns into an algorithm, and translate the algorithm into code.This part of the question involves writing Python code. Write your code in this file and then submit the completed code file as part of the answer to this part of the question.

Note:
Although Python has a built-in function to find the sum of a list, please do not use it to compute how many 1s there are in the list.
We want you to write your own code , because the purpose of this question is to practice following the problem solving approach described there, which will equip you to solve problems in other cases for which there is no built-in Python function.
A Python program which is not preceded by a corresponding decomposition will gain at most half marks. Again, the reason for this is that we want you to follow a systematic problem-solving approach and not dive straight into code. Please therefore make sure that you have supplied an answer to iv.
If you find it difficult to get the decomposition quite right at first there is no reason why you cannot review it when you have written the code. The main thing is to have a clear idea of what the solution needs to do (the decomposition) that ties in correctly with how it does it (the program).
Make sure you use appropriate variable names and comments and that you have tested your code with the inputs of your test table. (Keep each of your test inputs in your code, but precede all of the test inputs, except for one, with the # symbol. Recall that # signals a comment, which is ignored by the Python interpreter.)


0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
List Python
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • python In a program, write a function that accepts two arguments: a list, and a number...

    python In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display the number n, the list of numbers, and a sub list of all the numbers in the list that are greater than the number n. Initialize the list and the number n in the main function of your code and call your function, passing the list and number as arguments. Run your code...

  • volume_per_container python help

    Imagine that a company in the freight transport business has commissioned you to solve the following problem. Given bulk cargo with a certain weight per m3, compute the volume of that bulk cargo in m3 that a single 40-foot standard container can hold. A standard 40-foot container: has an internal volume of 67.5 m3 a maximum net load of 26199 kg . For instance, 1 m3 of gravel weighs 1800 kg. Because the maximum net load of a container is 26199 kg, a single container can only hold 14.555 m3 of gravel, otherwise it would exceed the maximum net load. For comparison, 1 m3 of wood chips weighs 380 kg. Because the maximum net load of a container is 26199 kg, based on the maximum weight, it is allowed to hold 68.94 m3 of wood chips. However, the internal volume of a single container is only 67.5 m3, so a single container can hold 67.5 m3 of wood chips. In answer to this question you will need to decompose the problem, write an algorithm, and implement the algorithm as a single python function that returns the total volume that can be held by single container. i.Include your initial decomposition of the problem in your solution document using the chevron notation (> and >>) ii.Include the algorithm for solving the problem in your solution document. Part iii of this question involves writing one Python function definition.  —— Draft Code—— def volume_per_container(kg_cargo_per_cubic_metre):     """Given the kg of cargo per cubic metre, calculate how many cubic metres of cargo can be stored in a single container."""     # INSERT YOUR CODE BELOW FOR CALCULATING THE      # TOTAL WEIGHT AND RETURNING THE RESULT (DO NOT CHANGE     # THE HEADER OF THE FUNCTION WHICH HAS BEEN PROVIDED FOR YOU     # ABOVE)      # DO NOT CHANGE THE CODE BELOW  # The code below automatically tests your function # If you run this file before making any changes to # it, you will get an AssertionError.  # Once you have completed the file with correct # code, the AssertionError should no longer appear and # message "tests passed" will appear in the shell. def test_volume_per_container():     """Test the volume_per_container function."""     # Test for gravel at 1800 kg per cubic metre      assert volume_per_container(1800) == 14.555          # Test for wood chips at 380 kg per cubic metre     assert volume_per_container(380) == 67.5          print ("tests passed")     test_volume_per_container() ——— End Draft Code———— Write your Python function definition for volume_per_container() in the draft code where indicated. Note that the Draft Code already contains code for automatically testing the function volume_per_container(). You must not change this code.  iv. Provide a Python function that implements the algorithm. Follow the instructions above for submitting code. Your answer must be a translation of your algorithm from part  (ii) above

  • In python Programming Exercise 1 Write a function that will have a list as an input,...

    In python Programming Exercise 1 Write a function that will have a list as an input, the task of the function is to check if all the elements in the list are unique,( i.e. no repetition of any value has occurred in the list), then the function returns true otherwise it returns false. Your program should include a main method that call the method to test it. Algorithm Analysis For the function you implemented in part 1, please calculate T(n),...

  • Develop an algorithm in PYTHON which incorporates decision making and Boolean logic, create a flowchart, and...

    Develop an algorithm in PYTHON which incorporates decision making and Boolean logic, create a flowchart, and then develop the code. The algorithm could be a classification algorithm, a process for solving a problem, or a few questions which help a user buy a car,

  • python language Problem Description: In this program we are going to explore a list or an...

    python language Problem Description: In this program we are going to explore a list or an array of integers using Python. Your program should read a set of integers from the user and store them in a list. Read numbers from the user until the user enters 0 to quit. Then store them in a list. Your program should them compute the sum of all the numbers in the list and output to the user. You will use lists and...

  • CAN SOMEONE PLEASE HELP AND ANSWER THIS Introduction to computing and IT question --------------------------------------...

    CAN SOMEONE PLEASE HELP AND ANSWER THIS Introduction to computing and IT question ---------------------------------------------------------------------------------------------------------------------------------------------------------------- this is the file required for the question Question 4 (14 marks) This question assesses Block 2 Part 4 a. This part of the question involves creating two drawings. You can make your drawings whichever way is easiest or fastest for you. For instance, you could simply make your drawings using pencil and paper then scan or photograph them. Consider the following two assignments: o languages-['java',...

  • PYTHON Fill in 3 numbers to complete the following 'list', as shown: 35 62 ___ 40...

    PYTHON Fill in 3 numbers to complete the following 'list', as shown: 35 62 ___ 40 ___ 18 ___ 1 55 28 add the month, day, and year you were born in the 3 spaces shown (in that order). (Use a 4-digit year.) Using the list of numbers above, write 4 different sort trace tables like those produced by the practice program linked above: Sort using the BubbleSort algorithm in ascending order. Sort using the BubbleSort algorithm in descending order....

  • In python, write the following program, high school question, please keep simple. When I submitted the...

    In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...

  • Write a Python function powerSet() that takes in a finite list object AA and returns P(A)P(A),...

    Write a Python function powerSet() that takes in a finite list object AA and returns P(A)P(A), the power set of A. The output should be only in the form of list objects. Note: Make sure you are familiar with some of Python's basic built-in list functions and operators, as they will make completing this problem far easier. For example: Test Result A = [0, 1, 2] output = set([frozenset(a) for a in powerSet(A)]) expected = [[], [0], [0, 1], [2],...

  • Python code The power set of a list L is a list containing all possible combinations of the eleme...

    python code The power set of a list L is a list containing all possible combinations of the elements of L. For example, the power set of [1, 2, 3] is [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]. Section 9.3 of your textbook describes a (subtle) algorithm for generating the power set. • Read and understand the structure of the code in Figure 9.6 • Write (your own) function powerset(L) that generates and returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT