5 of 6
Build a function for a Roblox shop that calculates the total cost of buying multiple items, with a bulk discount.
Write a function shop_total(price, quantity) that:
def shop_total(price, quantity): # Your code here pass # Test your function: print(shop_total(100, 3)) # Should print: 300 print(shop_total(100, 5)) # Should print: 450.0 (10% off 500) print(shop_total(200, 10)) # Should print: 1800.0 (10% off 2000) print(shop_total(50, 1)) # Should print: 50
First calculate total = price * quantity. Then check if quantity >= 5 to apply the discount.
10% discount means the player pays 90% of the total: total * 0.9
def shop_total(price, quantity): total = price * quantity if quantity >= 5: total = total * 0.9 return total
Write a function receipt(item_name, price, quantity) that prints a receipt like:
--- Receipt ---
Item: Diamond Sword
Price: 100 each
Quantity: 5
Total: 450.0 (10% discount applied!)
Use your shop_total function inside it!
def receipt(item_name, price, quantity): total = shop_total(price, quantity) print("--- Receipt ---") print(f"Item: {item_name}") print(f"Price: {price} each") print(f"Quantity: {quantity}") if quantity >= 5: print(f"Total: {total} (10% discount applied!)") else: print(f"Total: {total}")
β Standard library: heapq, collections, itertools, math, random, functools, datetime, bisect
β Functions, classes, recursion, print()
β No file system, subprocess, OS access, or network requests
β No pip install (all supported modules are pre-loaded)
β±οΈ 5 second execution time limit