To create an algorithm that implements the described discount logic, you can follow these steps and put the code in order accordingly:
- Get the user's spending total.
- Check if the spending total is greater than $200.
- If yes, apply a 20% discount.
- Else, check if the spending total is greater than $100.
- If yes, apply a 10% discount.
- If neither condition is met, inform the user that no discount applies.
- Output the discount percentage (if applicable) to the user.
Here's how that can be structured in Python code:
# 1. Get the user's spending total
spending_total = float(input("Enter your total spending: "))
# 2. Check if the spending total is greater than $200
if spending_total > 200:
discount_percentage = 20
discount_message = f"You get a {discount_percentage}% discount!"
# 3. Else, check if the spending total is greater than $100
elif spending_total > 100:
discount_percentage = 10
discount_message = f"You get a {discount_percentage}% discount!"
# 4. If neither condition is met
else:
discount_message = "No discount applies."
# 5. Output the discount percentage to the user
print(discount_message)
Explanation:
- The user's spending total is received as input.
- The first condition checks if spending exceeds $200 to grant a 20% discount.
- The second condition checks if spending is above $100 for a 10% discount.
- If neither condition is met, the user is informed that no discount applies.
- Finally, the result is printed to the user.