193k views
4 votes
) A small shop sells 280 different items. Each item is identified by a 3 – digit code. All items that start with a zero (0) are cards, all items that start with a one (1) are sweets, all items that start with a two (2) are stationery and all items that start with a three (3) are toys. Write an algorithm, using pseudocode, which inputs the 3 – digit code for all 280 items and outputs the number of cards, sweets, stationery and toys.

User Bestlion
by
4.5k points

1 Answer

3 votes

Answer:

cards, sweets, stationery, toys = 0

for i in range 0 to 280

Input the code

digit = int(code/100)

if digit == 0:

cards += 1

elif digit == 1:

sweets += 1

elif digit == 2:

stationery += 1

elif digit == 3:

toys += 1

output cards, sweets, stationery, toys

Step-by-step explanation:

- Set all the counts as zero at the beginning

- Initialize a for loop that iterates 280 times

- Ask user to enter the code

- Get the code's first digit by dividing 100

- Depending on the digit, increment the counts of the items

- When the loop is done, print the count of the items

User Schlenger
by
4.6k points