← 2023 questions

2023 / SHOPEE / QUESTION 31

Shopping cart

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

THE QUESTION

Valerie enjoys buying various items from Shopee.

Define each of the following products to be a variable with its value being the price of the product which you must decide (can be any number).

Shoes, Phone case, Suitcase, Earphones, T-shirt, Sunscreen, Microwave, Bath towel, Socks, Dried fruit

Create a user prompt that asks the user what item they would like to purchase (they can enter the number associated with the product e.g. 1 for Shoes). There should be at least 3 prompts so the user can add 3 items to the cart.

Create a variable that is equal to the total price of the items added by the user.

Create a condition that adds the price of the item chosen to that total price value.

Create a user prompt asking for the user to choose between the following discount coupons:

20% discount

10rm cashback

50% cashback (as a choice for purchases above RM150 only)

Create a condition that applies the appropriate discount to the total price value depending on the user’s choice.

Display the total amount to be paid by the user.

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

PRACTICE CHECK

Try your answer.

New prices and selections; the original exercise lets participants choose prices.

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 practice prices: Shoes RM50, Phone case RM20, Earphones RM30. Buy one of each and select the 20% discount. Enter the final amount.

Reveal worked answer

Discounted amount

80

(50 + 20 + 30) × 0.8 = RM80.