243. Python Program to Find a Gym Membership Price with Offers
EasyPhase 1 · Warm-up
You have used every tool here before: input(), if with elif, and f-strings with :.2f.
Overview
Gyms sell plans of different lengths, and a longer plan is cheaper for each month. Many also give students an offer: a lower price.
Problem Statement
Jamal works at the front desk of a gym. The plans are:
- 1 month: 30 coins.
- 6 months: 150 coins.
- 12 months: 240 coins.
Students get 15% off any plan.
Read the number of months and the student answer. Print the price with 2 decimal places, as Price: <price> coins. If the months are not 1, 6 or 12, print Months must be 1, 6 or 12 instead.
Steps
- Read the months as a whole number, and the student answer as text.
- Find the price of the plan for 1, 6 or 12 months.
- If the answer is
yes, take 15% off the price. - Print the price with 2 decimal places.
- For any other number of months, print the message instead.
Examples
Example 1. Input:
6
yes
gives:
Price: 127.50 coins
Why: the 6-month plan costs 150 coins. 15% of 150 is 22.5, and 150 - 22.5 = 127.5.
Example 2. Input:
3
no
gives:
Months must be 1, 6 or 12
Why: there is no 3-month plan, so there is no price to print.
Input
Two lines:
- The months, a whole number.
- The student answer:
yesorno, in small letters.
Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.
Output
One line: Price: <price> coins with 2 decimal places, or Months must be 1, 6 or 12. The tests try 6 different inputs.
Try it first. The solution opens when you solve this question, or after 3 tries with Submit.
This is the last question of Phase 1 · Warm-up. The next question starts Phase 2.