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]
4 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]4 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
Which of the following is NOT a provision of the Agricultural Adjustment Act? insurance for farmers alternative energy programs
Arisa [49]

Answer:

Farm equipment

Explanation:

Most people have heard claims that the US government pays farmers not to grow crops. The Agricultural Adjustment Act is the legislation that started this program. It was the first “Farm Bill.” The current farm bill provides for the following:

Subsidies for farmers

Insurance for farmers

Price supports

Food assistance for economically challenged Americans (the largest portion of the Farm Bill)

Forestry conservation programs

Alternative energy programs.

4 0
3 years ago
A function is different from a procedure because a functiondoes not contain a set of instructions.can have only a limited number
777dan777 [17]

Answer: A function returns a value and a procedure just executes commands.

Explanation:

6 0
2 years ago
Read 2 more answers
Troy must keep track of the amount of refrigerant he uses from a 50-pound cylinder to ensure that accurate
IgorLugansk [536]

Answer:

Amount of gas still in cylinder = 28 pound

Explanation:

Given:

Amount of gas in cylinder = 50 pound

Amount of gas used in Ms. Jones system = 13 pound

Amount of gas used in client system = 9 pound

Find:

Amount of gas still in cylinder

Computation:

Amount of gas still in cylinder = Amount of gas in cylinder - Amount of gas used in Ms. Jones system - Amount of gas used in client system

Amount of gas still in cylinder = 50 - 13 - 9

Amount of gas still in cylinder = 28 pound

7 0
3 years ago
Which of the following is correct regarding the principal stresses and maximum in-plane shear stresses? a. Principal stresses ca
ziro4ka [17]

Answer:

option B.

Explanation:

The correct answer is option B.

Principal stress is the maximum normal stress a body can have. In principal stress, there is purely normal stress. On principal plane shear stress is zero.

In-plane shear stress are the shear stress which is acting on the plane.

The statement which is correct regarding principle plane and shear stress is that The shear stress over principal stress planes is always zero.

4 0
3 years ago
Air at 25 C and 1 atm is flowing over a long flat plate with a velocity of 8 m/s. Determine the distance from the leading edge o
DIA [1.3K]

Answer:

Explanation:

Given data

Temprature of air=25^{\circ}

pressure =1 atm

velocity(V)=8m/s

From the table for air at 25^{\circ} and 1 atm

kinematic viscosity\left ( \nu\right )=1.562\times 10^{-5} m^{2}/s

Reynolds number for turbulent flow=5\times 10^{5}

and Re.no.=\frac{V \times X}{\nu }

therefore length where turbulent flows start is

X=\frac{\left ( Re.no.\right )\times \nu }{V}

X=0.976 m

Thickness of boundary layer is given by

\delta _x=\frac{5X}{\sqrt{Re_x}}

\delta _x=\frac{5\times 0.976}{\sqrt{5\times 10^5}}

\delta _x=6.901mm

for water

kinematic viscosity\left ( \nu\right )=8.91\times 10^{-7} m^{2}/s

Reynolds number for turbulent flow=5\times 10^{5}

and Re.no.=\frac{V \times X}{\nu }

therefore length where turbulent flows start is

X=\frac{\left ( Re.no.\right )\times \nu }{V}

X=0.055m

Thickness of boundary layer is given by

\delta _x=\frac{5X}{\sqrt{Re_x}}

\delta _x=\frac{5\times 0.055}{\sqrt{5\times 10^5}}

\delta _x=0.3889mm

5 0
3 years ago
Read 2 more answers
Other questions:
  • A gear and shaft with nominal diameter of 34 mm are to be assembled with a medium drive fit (H7/s6). The gear has a hub, with an
    9·1 answer
  • 1. Why is outside air mixed with return air?​
    6·1 answer
  • What steps would you take to design an improved toothpaste container?
    12·1 answer
  • Design a digital integrator using the impulse invariance method. Find and give a rough sketch of the amplitude response, and com
    15·1 answer
  • A cylindrical aluminum core is surrounded by a titanium sleeve, and both are attached at each end to a rigid end-plate. Set up t
    8·1 answer
  • Q#3:(A)Supose we extend the circular flow mode to add imports and export copy the circular flow digram onto a sheet paper and th
    15·1 answer
  • A steel plate has a hole drilled through it. The plate is put into a furnace and heated. What happens to the size of the inside
    9·1 answer
  • CODE
    13·1 answer
  • A book sitting on a shelf is an example of ____________.
    6·2 answers
  • When starting up a dual fuel system, the temperature rise method for determining airflow cannot be used with the compressor cycl
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!