Question

Put the following lines of code in order to create an algorithm for this situation: if you spend more than $200, you get a 20 percent discount. If you spend less than $200 but more than $100, you get a 10 percent discount. The user inputs their spending total, and the program tells them if they get a discount and, if so, what percentage the discount will be.

Answers

There are no human answers yet.
Answered by GPT-4o mini
To create an algorithm that implements the described discount logic, you can follow these steps and put the code in order accordingly:

1. **Get the user's spending total.**
2. **Check if the spending total is greater than $200.**
- If yes, apply a 20% discount.
3. **Else, check if the spending total is greater than $100.**
- If yes, apply a 10% discount.
4. **If neither condition is met, inform the user that no discount applies.**
5. **Output the discount percentage (if applicable) to the user.**

Here's how that can be structured in Python code:

```python
# 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:
1. The user's spending total is received as input.
2. The first condition checks if spending exceeds $200 to grant a 20% discount.
3. The second condition checks if spending is above $100 for a 10% discount.
4. If neither condition is met, the user is informed that no discount applies.
5. Finally, the result is printed to the user.

Related Questions