In: Computer Science
Create a new file name condition_quiz.py.
Add a comment with your name and the date.
Prompt the user to enter the cost. Convert the input to a float.
Prompt the user for a status. Convert the status to an integer
Compute the special_fee based on the status.
If the status is 0, the special_fee will be 0.03 of the cost.
Else if the status is 1, the special_fee will be 0.04 of the cost.
Else if the status is 2, the special_fee will be 0.06 of the cost.
Else if the status is 3 or 4, the special_fee, the special_fee will be 0.07 of the cost.
Otherwise, the special_fee will be 0.10 of the cost.
Compute the total_cost as the cost plus the special_fee. Print out the total_cost with two decimal places of precision.
Solution:-
Since there is no name specified so the comment in the code has been left empty.
Python 3 Code:-
# Name :
# Date : 8 October 2020
# Prompt the user to enter the cost
cost = float(input('Enter the cost: '))
# Prompt the user for a status
status = int(input('Enter the status: '))
# In case status is 0
if status == 0:
special_fee = 0.03 * cost
# In case status is 1
elif status == 1:
special_fee = 0.04 * cost
# In case status is 2
elif status == 2:
special_fee = 0.06 * cost
# In case status is 3 or 4
elif status == 3 or status == 4:
special_fee = 0.07 * cost
# Otherwise
else:
special_fee = 0.10 * cost
# Computing total cost
total_cost = cost + special_fee
# Printing total cost with two decimal places precision
print('Total cost: %.2f'%total_cost)
Code snapshot:-
Output snapshot:-