← 2023 questions

2023 / SHOPEE / QUESTION 35

Lowest price

Try the question in your own editor, then check your output below.

THE QUESTION

Valerie is trying to order a birthday gift for her mom from Shopee. She has looked at the catalogue available on Shopee, and now she needs to find the item that she wants to buy. Valerie has downloaded a text file from the Shopee website which contains the item information for each item in the catalogue. The text file is made up of two columns. The first column contains the item ID and the second column has the item name and item price. Valerie wants to find the item with the lowest price so that she can buy it for her mom. She is going to use Python functions to find the item with the lowest price. Valerie first needs to read in the text file using the open() function. She will then use the readlines() function to create a list of the items in the file. Next, Valerie needs to create an empty list to store the item prices. She will use a for loop to iterate through the list of items and store the item prices in the empty list. Now Valerie has a list of all the item prices, she can use the min() function to find the item with the lowest price.

This question requires you to create your own text file

Question by Eleonora. Source: Girls In Code SEA — Behind the Screens, 2023, slide 55.

PRACTICE CHECK

Try your answer.

New catalogue; the original question asks participants to create their own file.

Run your program in your own editor, then paste its output below. This checks the stated output or checkpoint; it does not assess your full program. Practice attempts do not affect competition scores.

New catalogue rows (ID, name, price): P1 Lamp 20; P2 Notebook 8; P3 Mug 12. Enter ID, name and price of the cheapest item.

Reveal worked answer

Cheapest item

P2 Notebook 8

Parse numeric prices and select the record with minimum price: 8.