livepython.net

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

  1. Read the months as a whole number, and the student answer as text.
  2. Find the price of the plan for 1, 6 or 12 months.
  3. If the answer is yes, take 15% off the price.
  4. Print the price with 2 decimal places.
  5. 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:

  1. The months, a whole number.
  2. The student answer: yes or no, 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.

Finish this chapter firstChapter 8 · If Statements

This is the last question of Phase 1 · Warm-up. The next question starts Phase 2.

solution.py
# write your code here

EXPECTED OUTPUT

1Price: 127.50 coins

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.