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
A plot of land is an irregular trangle with a base of 122 feet and a height of 47 feet what is the area of the plot?
Reika [66]

Answer:

150 is the area

Explanation:

3 0
3 years ago
An engineering firm just lost one of their larger customers. The firm president says that the solution to this problem is to fir
Shkiper50 [21]

Answer:

The engineers disagreed because their jobs were on the line

The ethical factors are:

The reason for the customer dumping the business is yet to be figured out

The need to keep cost to the lowest ebb in order to keep maintain profitability at the expense of employees' welfare

The are several ways of growing customer base which  are yet to be exploited.

Explanation:

The engineers disagree because there is no direct connection between the company's loss of the customer and their proposed layoff of the engineers,at least no one strong evidence has been given by the president.

The ethical factors inherent in this case are as follows:

The reason for the customer dumping the business is yet to be figure out

The need to keep cost to the lowest ebb in order to keep maintain profitability.

The are several ways of growing customer base which  are yet to be exploited.

There is  a need for a fact-finding exercise to establish the main motive behind losing such customer,without which the company can run into more troubles in future,otherwise the company would keep firing its good hands each time a customer dumps it.

Also,the president had resulted into such decision in order to maintain company's margins,where then lies ethics of welfare economics?Welfare economics is about looking beyond margins and looking at issues from a wider perspective of fulfilling the needs of employees in order for them to put in their best performance,at least by granting them job safety.

The company could have also grown business by investing in new technology that sets it apart from competitors instead of just jumping into the conclusions of sacking employees in a business where the company's strength lies in quality of engineers that it has.

7 0
3 years ago
How is the difference between science and engineering Best stated?
stiv31 [10]

Answer:Science is the body of knowledge that explores the physical and natural world. Engineering is the application of knowledge in order to design, build and maintain a product or a process

Explanation:

8 0
2 years ago
Which of the following describes how the author introduces dust storms in the text??​
Oduvanchick [21]

Answer:

B-as deadly storms that claim lives in th great pines

Explanation:

I hope it helped if it did pls make me brainliest

8 0
3 years ago
Read 2 more answers
By adding "-once", one can form the noun form of the word "organize" is that true or false?​
denpristay [2]

Answer:

<h2>False </h2>

Explanation:

The noun form of organize is just adding letter r

7 0
2 years ago
Read 2 more answers
Other questions:
  • A corroded metal gusset plate was found on a bridge. It was estimated that the original area of the plate was 750 cm2 and that a
    11·1 answer
  • Oil with a specific gravity of 0.72 is used as the indicating fluid in a manometer. If the differential pressure across the ends
    6·1 answer
  • Water enters a leaky cylindrical tank (D = 1 ft) at a rate of 8 ft3/min. Water leaks out of the tank at a rate of 17% of the flo
    14·1 answer
  • Before you calculate the moment capacity for a steel beam, you have to determine the classification of beam.
    10·1 answer
  • Give the approximate temperature at which creep deformation becomes an important consideration for each of the following metals:
    5·1 answer
  • Convert 25 mm into in.
    13·1 answer
  • What is engine knock? What cause the engine knock problem?
    5·1 answer
  • Phân tích phương pháp gia công plasma
    10·1 answer
  • Can U lose a rank in Brainly by using too many points?
    6·1 answer
  • Describe the first case where the power of synthesis was used to solve design problems.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!