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
The density of a certain type of steel is 8.1 g/cm3. What is the mass of a 100 cm3 chunk of this steel
irina1246 [14]

Answer:

  810 g

Explanation:

Mass is the product of density and volume:

  m = ρV

  m = (8.1 g/cm³)(100 cm³) = 810 g

The mass of the chunk is 810 grams.

4 0
2 years ago
Conduct online research and write a short report on the origin and evolution of the meter as a measurement standard. Discuss how
valina [46]

Answer:

People have come up with all sorts of inventive ways of measuring length. The most intuitive are right at our fingertips. That is, they are based upon the human body: the foot, the hand, the fingers or the length of an arm or a stride.

In ancient Mesopotamia and Egypt, one of the first standard measures of length used was the cubit. In Egypt, the royal cubit, which was used to build the most important structures, was based on the length of the pharaoh’s arm from elbow to the end of the middle finger plus the span of his hand. Because of its great importance, the royal cubit was standardized using rods made from granite. These granite cubits were further subdivided into shorter lengths reminiscent of centimeters and millimeters.

piece of black rock with white Egyptian markings

Fragment of a Cubit Measuring Rod

Credit: Gift of Dr. and Mrs. Thomas H. Foulds, 1925

Later length measurements used by the Romans (who had taken them from the Greeks, who had taken them from the Babylonians and Egyptians) and passed on into Europe generally were based on the length of the human foot or walking and multiples and subdivisions of that. For example, the pace—one left step plus one right step—is approximately a meter or yard. (On the other hand, the yard did not derive from a pace but from, among other things, the length of King Henry I of England’s outstretched arm.) Mille passus in Latin, or 1,000 paces, is where the English word “mile” comes from.

And thus, the meter has and likely will remain so elegantly defined in these terms for the foreseeable future.

Explanation:

is this short enough

5 0
3 years ago
How would I find the Voltage across the open circuit
Nimfa-mama [501]

Answer:

  Vab = 80V

Explanation:

The only current flowing in the circuit is supplied by the 100 V source. Its only load is the 40+60 ohm series circuit attached, so the current in that loop is (100V)/(40+60Ω) = 1A. That means V1 = (1A)(60Ω) = 60V.

Vab will be the sum of voltages around the right-side "loop" between terminals 'a' and 'b'. It is (working clockwise from terminal 'b') ...

  Vab = -10V +60V +(0A×10Ω) +30V

  Vab = 80V

3 0
2 years ago
What is the focus of 7th grade civics
Jobisdone [24]
C. seems like the best answer. i may be wrong so don’t quote me on that
7 0
3 years ago
Read 2 more answers
Anna makes arrangements to reuse waste water that has been used in sinks and showers. Which term refers to the waste water that
victus00 [196]

Answer:

Greywater.

Explanation:

Greywater is also known as sullage and it can be defined as any form of gently used wastewater derived from sources within a residential or office building such as showers, washing machines, bathroom sinks, bathroom tub, etc.

Generally, greywater or sullage is completely free of fecal materials (faeces) because it is independent from all toilet activities. However, greywater is not clean for direct use because it usually contains food particles, dirt, oil from dishes, hair, etc.

In this scenario, Anna makes arrangements to reuse waste water that has been used in sinks and showers. Greywater is a term which refers to the waste water that Anna reuses to conserve resources.

Therefore, Anna reuses greywater to conserve resources.

8 0
3 years ago
Other questions:
  • A 10-kg block A is released from rest 2 m above the 5-kg plate P, which can slide freely along the smooth vertical guides BC and
    6·1 answer
  • There are 20 forging presses in the forge shop of a small company. The shop produces batches of forgings requiring a setup time
    10·1 answer
  • One cylinder in the diesel engine of a truck has an initial volume of 650 cm3 . Air is admitted to the cylinder at 35 ∘C and a p
    7·1 answer
  • Create a project named CarDealer that contains a Form for an automobile dealer. Include options for at least three car models. A
    14·1 answer
  • Which one is dependent variable?
    13·1 answer
  • Steven is starting a project that requires a specialized, experienced contractor. Which selection process is the most suitable f
    11·1 answer
  • At a certain location, wind is blowing steadily at 7 m/s. Determine the mechanical energy of air per unit mass and the power gen
    14·1 answer
  • What do you think causes the differences in the properties of oxygen gas (O2) and ozone (O3)? the space between the atoms the ra
    9·1 answer
  • Guyss I seriously and urgently need help what are the steps to build a headgear ??​
    5·2 answers
  • During delivery of a 2023 ariya equipped with propilot assist 2. 0, what should you point out to your customers about the turn s
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!