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
Please help this is due today!!!!!
White raven [17]

Answer:

1:c 2:False

Explanation:

7 0
3 years ago
Air (cp = 1.005 kJ/kg·°C) is to be preheated by hot exhaust gases in a cross-flow heat exchanger before it enters the furnace. A
uysha [10]

Answer:

Q=67.95 W

T=119.83°C

Explanation:

Given that

For air

Cp = 1.005 kJ/kg·°C

T= 20°C

V=0.6 m³/s

P= 95 KPa

We know that for air

P V = m' R T

95 x 0.6 = m x 0.287 x 293

m=0.677 kg/s

For gas

Cp = 1.10 kJ/kg·°C

m'=0.95 kg/s

Ti=160°C   ,To= 95°C

Heat loose by gas = Heat gain by air

[m Cp ΔT] for air =[m Cp ΔT] for gas

by putting the values

0.677 x 1.005 ( T - 20)= 0.95 x 1.1 x ( 160 -95 )

T=119.83°C

T is the exit temperature of the air.

Heat transfer

Q=[m Cp ΔT] for gas

Q=0.95 x 1.1 x ( 160 -95 )

Q=67.95 W

7 0
3 years ago
Given a square matrix [A], write a single line MATLAB command that will create a new matrix [Aug] that consists of the original
Liono4ka [1.6K]

Answer:

Consider A is square matrix of order 4 x 4 generated using magic function. Augmented matrix can be generated using:

Aug=[A eye(size(A))]

Above command is tested in MATLAB command window and is attached in figure below

8 0
3 years ago
I want a problems and there solutions of The inception of cavitation?​
Ugo [173]

Answer:

The overview of the given scenario is explained in explanation segment below.

Explanation:

  • The inception of cavitation, that further sets the restriction for high-pressure and high-free operation, has always been the matter of substantial experimental study over the last few generations.
  • Cavitation inception would be expected to vary on the segment where the local "PL" pressure mostly on segment keeps falling to that are below the "Pv" vapor pressure of the fluid and therefore could be anticipated from either the apportionment of the pressure.

    ⇒  A cavitation number is denoted by "σ" .

4 0
3 years ago
A thin-walled cylinder of average radius 50 mm, and wall thickness 1.0 mm is of length 500 mm, and is built into a wall at one e
kotykmax [81]

Answer:

0

Explanation:

7 0
3 years ago
Other questions:
  • What can your employer do to protect you from overhead power lines?
    8·1 answer
  • Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containe
    5·1 answer
  • Does a thicker core make an electromagnet stronger?
    13·1 answer
  • (Signal Property) Under what condition is a discrete-time signal x[????] or a continuous-time signal x(????) periodic? Determine
    5·1 answer
  • potential difference is the work done in moving a unit positive charge from one point to another in an electric field. State Tru
    12·1 answer
  • By using order of magnitude analysis, the continuity and Navier-Stokes equations can be simplified to the Prandtl boundary-layer
    9·1 answer
  • How can you drop two eggs the feweHow can you drop two eggs the fewest amount of times, without them breaking? ...st amount of t
    13·2 answers
  • Estimate the luminosity of a 3 -solar-mass main-sequence star; of a 9 -solar-mass main-sequence star. Can you easily estimate th
    5·1 answer
  • You should use the pass technique a fire extinguisher
    8·1 answer
  • What is the effect of connecting
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!