Inicio
/
Tecnología
/
Shoppers at a Mall Were Asked Whether They Preferred Wearing Gloves or Mittens in Cold Weather. Shoppers' Preferences Were Stored in

Problemas

Shoppers at a mall were asked whether they preferred wearing gloves or mittens in cold weather. Shoppers' preferences were stored in the list votelist as strings, with the string "Gloves" representing a preference for gloves and the string "kittens" representing a preference for mittens. The following code segment is intended to traverse the list and display the number of shoppers who chose gloves and the number of shoppers who chose mittens. numGlovesvotes +- 0 numittensvotes + 0 CHISSING COOES f IF(vote = "Gloves") nunsiovesvotes +- numblovesvotes +1 ELSE f numsittensvotes +-numiltensivetes +1 ) DISPLAY(nunglovesVotes) DISPLA I(" shoppers chose gloves and") DISPLAY (numittensvotes) DISPLAY(" shoppers chose mittens .", Which of the following should replace outssting cook so that the code segment works as intended? A IF(voteleqslant LENGTH(voteList)) B FOR EACH vote IN votelist C D REPEA UTIL(VOte) LENGTH(votelist) REPEAT LEIGTH(VOteList) TIVES

Roztwór

Agustín maestro · Tutor durante 5 años
Weryfikacja ekspertów
4.4 (199 Votos)

Respuesta

The correct answer is B. FOR EACH vote IN votelist.Explanation:The code segment is intended to traverse the list and display the number of shoppers who chose gloves and the number of shoppers who chose mittens. To achieve this, we need to use a loop that iterates through each element in the votelist.Option B, "FOR EACH vote IN votelist", is the correct choice because it creates a loop that will iterate through each element in the votelist. Inside the loop, we can check if the vote is "Gloves" or "mittens" and update the corresponding vote count.The other options are not correct:A. "IF (vote <= LENGTH (voteList))" is not a valid loop statement and does not make sense in this context.C. "REPEAT LENGTH (voteList) TIMES" is not a valid loop statement and does not make sense in this context.D. "REPEAT LENGTH (voteList) TIMES" is not a valid loop statement and does not make sense in this context.Therefore, the correct answer is B. FOR EACH vote IN votelist.