In: Computer Science
Implement the following function in the PyDev module functions.py and test it from a PyDev module named :
def gym_cost(cost, friends): """ ------------------------------------------------------- Calculates total cost of a gym membership. A member gets a discount according to the number of friends they sign up. 0 friends: 0% discount 1 friend: 5% discount 2 friends: 10% discount 3 or more friends: 15% discount Use: final_cost = gym_cost(cost, friends) ------------------------------------------------------- Parameters: cost - a gym membership base cost (float > 0) friends - number of friends signed up (int >= 0) Returns: final_cost - cost of membership after discount (float) ------------------------------------------------------ """
Sample testing:
Gym membership cost: $50 Number of friends signed up: 2 Your membership cost is $45.00
Test functions.py:
CODE:
OUTPUT:
Raw_code:
#function defintion of gym_cost
def gym_cost(cost,friends):
#if the friends is 0 no discount
if(friends==0):
final_cost=cost+0
#if the friends is equal to 1 you get 5% discount
elif(friends==1):
final_cost=cost-(cost*0.05)
#if the friends is equal to 2 you get 10% discount
elif(friends==2):
final_cost=cost-(cost*0.1)
#if the friends are greater than or equal to 3 15% discount
elif(friends>=3):
final_cost=cost-(cost*1.5)
#returning final_cost
return final_cost
#a gym membership base cost
cost=float(input("Gym membership cost:$"))
friends=int(input("Number of friends signed up:"))
#if the cost is greater than 0 and the friends are greater than
equal to zero
if(cost>0 and friends>=0):
#calling the gym_cost wuth parameters(cost,friends)
final_cost=gym_cost(cost,friends)
#printing the final cost
print("Your membership cost is $",final_cost)
Note:I done this program in python IDLE due to unavailable of
PyDev
***********For any queries comment me in the comment
box************