- Part 5 Gas Rewards Program 10 Points Imagine A Gas Station That Offers A Rewards Program When A Customer Buys Gas 1 (425.91 KiB) Viewed 26 times
▾ Part 5: Gas Rewards Program (10 points) Imagine a gas station that offers a rewards program. When a customer buys gas,
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
▾ Part 5: Gas Rewards Program (10 points) Imagine a gas station that offers a rewards program. When a customer buys gas,
▾ Part 5: Gas Rewards Program (10 points) Imagine a gas station that offers a rewards program. When a customer buys gas, he or she is rewarded with points that can be used to purchase other goods. Complete the function gas_reward, which takes the following arguments, this order: current points: the current rewards points (an integer) on the customer's gas rewards card gas_type: the type of gasoline purchased (a string), which is one of the following: O 'Regular': $4.65/ gallon 'Plus': $4.90/gallon O 'Premium': $5.10/gallon • money spent: the amount f dollars spent on gas in a particular transaction. This number is needed to compute how many gallons of gas were purchased. After each gas purchase, the customer earns a certain number of rewards points. The function calculates and returns the updated, new total rewards points for the customer. The rewards rules are as follows: 1. Normally, 5 points are rewarded for every full gallon of gas purchased. For example, 6.83 gallons purchased will result in 5x6 = 30 new rewards points. Hint: given a floating-point variable x, the code int (x) will truncate x, thereby giving only the integer part of x: integer part = int(x). 2. If at least 10 gallons of gas were purchased, the customer will be rewarded 200 points 3. If at least 15 gallons of gas were purchased, the customer will be rewarded 400 points 4. If at least 20 gallons of gas were purchased, the customer will be rewarded 550 points Note: Only one of the above rules can be applied per transaction, namely, the one that benefits the customer most. For example, if a customer bought 16 gallons of gas, he/she will get 400 and only 400 reward points. Rule 1 is applied for purchases of less than 10 gallons. Below are some special cases that the function must handle. Your code should check for these special cases in this order: • If money_spent is less than one dollar, this is considered an invalid transaction, and the function returns current_points. • If current points is less than 0, this is considered a faulty account, and the function returns 'error' (a string). You may assume that gas_type is always valid. Examples: Function Call Return Value 2395 870 5333 gas_reward (1995, 'Regular', 74.00) gas_reward (870, 'Regular', 0.05) gas_reward (4933, 'Plus', 76.50) gas_reward (393, 'Plus', 0.75) gas_reward (1981, 'Plus', 5.83) gas_reward (3033, 'Premium', 54.06) 393 1986 3233 1817 gas_reward (1792, 'Plus', 25.58) gas_reward (4666, 'Regular', 57.73) gas_reward (-5, 'Plus', 58.90) 4866 error