Complete the trace table using the program in Figure 1.
def compute_cost(quantity, rate, discount):
if discount == 0:
return quantity * rate
else:
return (quantity * rate) - discount
numItems = int(input("Enter quantity: "))
price = int(input("Enter unit price: "))
reduction = int(input("Enter discount: "))
total = compute_cost(numItems, price, reduction)
if reduction == 0:
print(f"Standard {total}")
else:
print(f"Special {total}")
| numItems | price | reduction | Final output |
|---|---|---|---|
| 4 | 10 | 0 | [Answer 1] |
| 5 | 8 | 12 | [Answer 2] |
| 2 | 15 | 5 | [Answer 3] |
298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.