Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON PLEASE! and some comments/explanations along the way would be really help

ID: 3577204 • Letter: P

Question

PYTHON PLEASE! and some comments/explanations along the way would be really helpful in order to follow along! thank you!! :)

define tickets (number, is_member). It calculates and returns the price for number people to visit the museum(always a positive int); if anyone in the group has a membership(boolean is_member), they get a better deal. non-members : tickets are $10 each. Groups of 10 or more pay $8 per ticket members : first 6 of the group are free; tickets are $5 each beyond that.

ex. tickets(5, false) --- 50 #5*10

tickets(6, True) --- 0 # free

tickets(11, False) ---- 88 # 11*8

tickets(10, True) --- 20 # 4*5

Explanation / Answer


#Python 3.4
#The python program that tests the method tickets
#main method
def main():
    #calling tickets for four cases
    print(tickets(5, False))# --- 50 #5*10
    print(tickets(6, True))# --- 0 # free
    print(tickets(11, False))#---- 88 # 11*8
    print(tickets(10, True)) #--- 20 # 4*5

#Method tickets
#Input : number , is_member
#Return value :cost value
def tickets(number, is_member):

    #set value for NON_MEMBERS=10
    NON_MEMBERS=10
    MEMBER=5
    #set cost =0
    cost =0

    #check if is_member is True a number is <10
    if is_member==True and number<=6:
        #No cost
        cost=0
    elif is_member==True and number>=10:
        #remove first 6 numbers and
        cost=(number-6)*MEMBER
    elif is_member==False and number<10:
        cost=number*NON_MEMBERS      
        #check if is_member is False a number is <10
    elif is_member==False and number>=10:
        cost=number*8

        #return cost
    return cost


main()

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

Sample output:

>>>
50
0
88
20