1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Paraphin [41]
3 years ago
7

A manager has a list of items that have been sorted according to an item ID. Some of them are duplicates. She wants to add a cod

e to the database that assigns a 1 to the item if it is​ unique, and if there are​ duplicates, assigns the number of the duplicate. An example is shown below. The first two items are​ unique, so the repeat code is 1.​ However, Item ID 37699 is listed six​ times, so the codes are assigned from 1 to​ 6, and so on. Explain how to assign the correct code using an IF statement.
Engineering
1 answer:
ruslelena [56]3 years ago
6 0

Answer:

The solution code is written in Python:

  1. items = [{"id": 37697, "code": ""},{"id": 37698, "code": ""},{"id": 37699, "code": ""},{"id": 37699, "code": ""}, {"id": 37699, "code": ""},
  2. {"id": 37699, "code": ""},{"id": 37699, "code": ""},{"id": 37699, "code": ""},{"id": 37700, "code": ""} ]
  3. items[0]["code"] = 1
  4. for i in range(1, len(items)):
  5.    if(items[i]["id"] == items[i-1]["id"]):
  6.        items[i]["code"] = items[i-1]["code"] + 1
  7.    else:
  8.        items[i]["code"] = 1
  9. print(items)

Explanation:

Firstly, let's create a list of dictionary objects. Each object holds an id and a code (Line 1-2). Please note all the code is initialized with zero at the first beginning.

Next, we can assign 1 to the <em>code</em> property of items[0] (Line 4).

Next, we traverse through the items list started from the second element (Line 6). We set an if condition to check if the current item's id is equal to the previous item (Line 7). If so, we assign the previous item's code + 1 to the current item's code (Line 8). If not, we assign 1 to the current item's code (Line 10).

At last, we print out the item (Line 12) and we shall get

[{'id': 37697, 'code': 1}, {'id': 37698, 'code': 1}, {'id': 37699, 'code': 1}, {'id': 37699, 'code': 2}, {'id': 37699, 'code': 3}, {'id': 37699, 'code': 4}, {'id': 37699, 'code': 5}, {'id': 37699, 'code': 6}, {'id': 37700, 'code': 1}]

 

You might be interested in
What do we need to do to get CO2 emissions all the way to zero?
Svetlanka [38]

Answer:

A key element is powering economies with clean energy, replacing polluting coal - and gas and oil-fired power stations - with renewable energy sources, such as wind or solar farms. This would dramatically reduce carbon emissions. Plus, renewable energy is now not only cleaner, but often cheaper than fossil fuels

Explanation:

here is your answer if you like my answer please follow

3 0
2 years ago
Which of the following is NOT true about hydraulic valves? A. Directional control valves determine the path of a fluid in a give
Lelechka [254]

Answer: Option D is not true of hydraulic valves. A hydraulic valve is a device that can change the opening degree of liquid flow path

Explanation:

The pilot check valve allows flow of liquid in one direction and blocks flow in the opposite direction

5 0
3 years ago
One good way to improve your gas Milage is to ___.
VashaNatasha [74]

Answer: B

Explanation:

One good way to improve your gas mileage is to accelerate smoothly and directly to a safe speed.

Hope this helps!

5 0
2 years ago
Read 2 more answers
Am I alive I really need to know?
Nesterboy [21]
Hell no,cause i’m not
5 0
3 years ago
Initially, a pump pressure of __________ pounds per square inch should be used to maintain a sprinkler or standpipe system.
jasenka [17]

<u>Answer:</u>

<u>of 150 pounds per square inch</u>

Explanation:

Note that the unit for measuring water pressure is called <u> pounds per square inch (psi)</u>

In the case of sprinklers and standpipe systems, a pressure <u>of 150 pounds per square inch</u> was used initially.

6 0
3 years ago
Other questions:
  • The natural variation of a process relative to the variation allowed by the design specifications is known as
    15·1 answer
  • How does the two-stroke Otto cycle differ from the four-stroke Otto cycle?
    6·1 answer
  • A 36 ft simply supported beam is loaded with concentrated loads 16 ft inwards from each support. On the left side, the dead load
    7·1 answer
  • Before turning in a test, it would be best to
    6·2 answers
  • Every two years or at recommendation by manufacturer.
    10·1 answer
  • Select the correct answer <br><br> What is the simplest definition of a manufacturing process?
    5·2 answers
  • 13. Which stroke of the four-stroke cycle is shown in the above figure?
    6·1 answer
  • In the engineering design and prototyping process, what is the advantage of drawings and symbols over written descriptions?
    13·1 answer
  • The volume of microbial culture is observed to increase according to the formula
    15·1 answer
  • The web page you created displays the time in the correct time zone for the user's location.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!