Use the code to answer the question.

def discount_on_voucher(voucher, amount):
discount = 0
if voucher == 'Flat 50':
discount = 0.5 * amount
elif voucher == 'Flat 30':
discount = 0.3 * amount
elif voucher == 'Flat 20':
discount = 0.2 * amount
return discount

disc = discount_on_voucher('Flat 75', 1000)
print(f'Discount is {disc}')
What will be the output of the code? Execute your code using the Trinket.

Trinket

(1 point)
Responses

The output will be “Discount is 150.”
The output will be “Discount is 150.”

The output will be “Discount of 1000.”
The output will be “Discount of 1000.”

The output will be “Discount is 0.”
The output will be “Discount is 0.”

The output will be “Discount is 200.”

1 answer

To determine the output of the provided code, let's analyze it step by step.

The code includes a function discount_on_voucher(voucher, amount) that calculates a discount based on the given voucher type and amount. The possible vouchers and their corresponding discount percentages are:

  • 'Flat 50' gives a discount of 50% (0.5 * amount)
  • 'Flat 30' gives a discount of 30% (0.3 * amount)
  • 'Flat 20' gives a discount of 20% (0.2 * amount)

If the voucher does not match any of these options, the discount remains zero.

In the provided code, the following line executes the function with an invalid voucher:

disc = discount_on_voucher('Flat 75', 1000)

Since 'Flat 75' does not match any of the defined cases in the function, the discount variable stays initialized at 0.

The return value from the function will be 0. Consequently, the printed output will be:

print(f'Discount is {disc}')

This will result in:

Discount is 0.

Thus, the correct response is:

The output will be "Discount is 0."