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
A glass plate is subjected to a tensile stress of 40 MPa. If the specific surface energy is 0.3 J/m2 and the modulus of elastici
Pavlova-9 [17]

Answer:

8.24μm

Explanation:

The theory of brittle fracture was used to solve this problem.

And if you follow through with the attachment made a the subject of the formula

Such that,

a = 2x(69x10⁹)x0.3/pi(40x10⁶)²

= 4.14x10¹⁰/5.024x10¹⁵

= 8.24x10^-06

= 8.24μm

This is the the maximum length of the surface flaw

4 0
3 years ago
If you are involved in a collision where there is injury, you must report the incident within .......
Misha Larkins [42]

Answer:

24 hours

Explanation:

you must exchange insurance details after a collision if someone is injured. Otherwise you must report the collision to us as soon as possible (and no later than 24 hours). Although you must report such a collision straight away you should always seek medical help in the first instance.

4 0
3 years ago
How s the weather like​
scoray [572]

weather is like corono everywhere #stay safe

3 0
3 years ago
Which is an example of a subsystem and system relationship?
Zanzabum

The example of a subsystem and system relationship is option

A) mechanical toggle, Xbox controller

Explanation:

  • Controls and Controllers are known as the mechanical, electro-mechanical, or electronic devices which are used to  input signals to change the conditions or values which are in processes or access to buildings, operators, gated areas, etc.
  • When you press and hold the given Shift button, these buttons which are chosen becomes an alternate inputs.
  • Normally, there are three controllers(PID) which are used in any of the process industries inorder to maintain and control the required setpoint.
  • an example of a subsystem and system relationship is a mechanical toggle, Xbox controller
  • Controllers improve the steadiness and state of accuracy by decreasing the steady state error. When the steady state accuracy gets better, the stability also improves.
  • Controllers are also used to help in reducing the unwanted offsets which are produced by the system.

6 0
3 years ago
Think about all the things we have investigated in class so far this semester. Identify three examples of climate-related aspect
Free_Kalibri [48]

Answer:

1) the mean surface temperature of earth.

2) precipitation and sunshine

3) air and wind movement.

6 0
3 years ago
Other questions:
  • A cylindrical specimen of brass that has a diameter of 20 mm, a tensile modulus of 110 GPa, and a Poisson’s ratio of 0.35 is pul
    13·1 answer
  • State 2 reasons on why blind spot checks are important
    5·1 answer
  • How are scientific discoveries used in engineering design?
    12·1 answer
  • A very large plate is placed equidistant between two vertical walls. The 10-mm spacing between the plate and each wall is filled
    11·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
  • Two common methods of improving fuel efficiency of a vehicle are to reduce the drag coefficient and the frontal area of the vehi
    14·1 answer
  • 18
    14·1 answer
  • Describe the are of mechanical engineering
    6·2 answers
  • All of these are true about GMA (MIG) welding EXCEPT that:
    12·1 answer
  • Which of the following is a purpose of sports biomechanics?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!