← 2023 questions

2023 / SHOPEE / QUESTION 36

Compare sellers

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

THE QUESTION

Valerie is a Shopee user. She really likes buying tech-related stuff. Recently she has been looking to buy a Xiaomi 13, but is not sure which seller to buy from. Using the below dictionary, write a program for Valerie that tallies and displays the total cost of buying a Xiaomi 13 from each seller (including delivery fees and available discounts) then sorts them from least expensive to most expensive, telling her which ones she can afford. She starts with a random amount of money in her account between RM3000 and RM5000.

Valerie must then be able to select which seller she wants to visit and is given the option to buy the product or exit the seller’s page. Visiting a seller’s page clears the previous list from the screen.

If ‘buy’ is chosen, the program must check whether she has enough money in her account. If she does, she’ll be asked for her pin number (the pin number must be 6 digits long and must be a specific permutation of integers). Getting the pin number right will allow her to proceed with the purchase, while getting the pin number wrong more than twice in a row will suspend her account for 365 days. If she doesn’t have enough money, invalidate the purchase.

If ‘exit’ is chosen, the program will clear the screen and return to the previous list.

xm13 = {'Official Xiaomi Store' : {'price' : 2999.0, 'dis%' : 30}, 'Official Siaome Store' : {'price' : 0.99, 'dis%' : 90}, 'mmgbpmall' : {'price' : 3499.0, 'dis%' : 40}, 'spraygadget' : {'price' : 4599.0, 'dis%' : 25}, 'calastore' : {'price' : 1905.0, 'dis%' : 33}, 'mayatech' : {'price' : 2555.0, 'dis%' : 22}, 'mcdecotech' : {'price' : 2359.0, 'dis%' : 20}, 'caviar' : {'price' : 59999.0, 'dis%' : 0}, 'rocketgadgets' : {'price' : 3349.0, 'dis%' : 12}, 'realstore' : {'price' : 20.0, 'dis%' : 50}}

Question by Yu Shen. Source: Girls In Code SEA — Behind the Screens, 2023, slide 56.

PRACTICE CHECK

Try your answer.

New fixed balance and delivery fees (fees were absent from the source). This checks costs and affordability; PIN and purchase flows require manual review.

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.

Practice convention: delivery is RM0 for every seller. Apply the given percentage discounts. Enter seller names from cheapest to most expensive.

Use a practice balance of RM3000. Enter every affordable seller.

Reveal worked answer

Seller order

["Official Siaome Store", "realstore", "calastore", "mcdecotech", "mayatech", "Official Xiaomi Store", "mmgbpmall", "rocketgadgets", "spraygadget", "caviar"]

Affordable sellers · one valid answer

["Official Siaome Store", "realstore", "calastore", "mcdecotech", "mayatech", "Official Xiaomi Store", "mmgbpmall", "rocketgadgets"]

Price after discount = price × (1 − discount/100). Sort these totals and compare each against RM3000.