In: Computer Science
(Python language)
Going out with the gang?
You are planning an outing with some friends and need to calculate the total price of the tickets. A regular ticket usuallycosts$3.99 and a student ticket costs only $2.99. If the total number of tickets being ordered (including both students andregular tickets) is at least 10, then a 10% discount is applied to the order. However, if it is a holiday, then the at-least-tengroup discount is only 5% (not 10%).Write a functiontotalticketprice: given three parameters (the number of regular tickets, the number of studenttickets, and whether or not it is a holiday), compute and return the total. Be sure to define and use constants forREGULARTICKETPRICEandSTUDENTTICKETPRICE. We’ll check for this.
Is it time for tea?
Your friend lives in London, England in a timezone that is normally 6−hours ahead of Toronto, Canada. But sometimesEngland and Canada switch to daylight savings time on different dates. If Toronto is on daylight savings time and Londonis not, then the time difference is only 5−hours. Conversely, if London is on daylight savings time and Toronto is not, thetime change is 7−hours. Of course, if both are on daylight savings time, the difference is back to the standard 6−hours. Write the functionbritishtimewhose first parameter is a float value representing the time in Toronto as 24-hour time.The next two parameters are booleans indicating whether Toronto and London are on daylight savings time, respectively.Your function should return the time in London as a float.One last complication is that your function should not return a time greater or equal to 24.0 or less than 0.0.Suggestion: at first do not consider this final complication and write test cases where the expected output is already less than24.0(in the same day). Once that is working, add a test case where the time in Toronto is so late at night that London isalready the next morning. Fix the body of your function to work correctly.For the purpose of this lab, afunctiontakes some input (not always) and returns some output (not always). Go back and makesure that none of your functions print anything!Printing is notthe same as returning!
def totalticketprice(no_of_regular_tickets, no_of_student_tickets, is_holiday):
price_sum = no_of_student_tickets * 2.99 + no_of_regular_tickets * 3.99
discount = 0 #initally discount percentage is 0
if no_of_regular_tickets+no_of_student_tickets >= 10:
if is_holiday:
discount = 5
else:
discount = 10
discount = discount/100 * price_sum #calculate total discount on price_sum from discount percentage
price_sum = price_sum - discount
return price_sum
Above is the python function for question 1 Going out with the gang?
It is well commented for your understanding. It has three parameters : no_of_student_tickets, no_of_regular_tickets, and a boolean variable is_holiday (which is True/1 if it is a holiday otherwise False/0).
Note: As you have not mentioned, it is assumed only the first question is to be answered as per our policy. But If you still help in Q2, please let me know the correct input format for 24 hour time by giving a sample example as it is not clear from the question. Thanks and let me know if you have any doubts in the above solution.