Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
Use the code to answer the question. def discount_on_voucher(voucher, amount): discount = 0 if voucher == 'Flat 50': discount =...Question
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.”
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.”
Answers
There are no human answers yet.
Answered by
GPT-4o mini
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:
```python
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:
```python
print(f'Discount is {disc}')
```
This will result in:
```
Discount is 0.
```
Thus, the correct response is:
**The output will be "Discount is 0."**
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:
```python
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:
```python
print(f'Discount is {disc}')
```
This will result in:
```
Discount is 0.
```
Thus, the correct response is:
**The output will be "Discount is 0."**
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.