In: Computer Science
'PYTHON'
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass in 150.78 and True. Call the function from within main() and pass in 98.23 and False. Print out the returned discounted cost with two decimal places of precision in the main function.
2. Add annotations and comments to the compute_discount()
function. Call the appropriate functions from within main() to
display the annotations and comments and print the output.
3. a. Create a new file (module) named camera_picture.py.
b. Write a function, take_picture_effect, that takes two
parameters, the filename and an effect.
c. Take a picture with the filename and effect. Use camera.effect
to set the effect. Use help(PiCamera) to find the effects which you
can apply.
d. Create a second file use_camera.py.
e. Import the take_picture_effect function from the camera_picture
module.
f. Prompt the user for the filename.
g. Prompt the user for the image_effect. help(PiCamera) to see the
list of image effects.
h. Call the function with the filename and the effect as
arguments.
3. Write a function that prints a menu that allows the user to
select an effect with a letter. Call the take_picture_effect
function with the appropriate arguments.
a. cartoon
b. pastel
c. emboss
etc.
(BONUS)
a. Create a new file (module) named light_sound.py.
b. Write a function, alert_fun that takes three parameters, the
GPIO pin for the LED, the GPIO pin for the Buzzer, and the duration
of the light to be on and the buzzer to sound.
c. Create a second file use_light_sound.py.
d. Import the alert_fun function from the light_sound module.
e. Prompt the user for the GPIO pin for the LED, the GPIO pin for
the Buzzer, and the duration.
d. Call the function with the duration as an argument.
Answer
Here is your answer, if you have any doubt please comment, i am here to help you,
a) Here is your answer in python for the above problem, Here some doubt regarding cyber tuesday, Actually we don't know which date is considered as cyber tuesday. In 2020, cyber monday is november 30. So in your code i take cyber tuesday as cyber monday, please change the date according to your knowledge about cyber tuesday. Just change the date thats enough.
Here is the code.
from datetime import *
def compute_discount(cost,ismember):
'''
Function defining here, Accepting two values from main , and calculate the discount based on the condition.
'''
if ismember==True:
final_cost=cost+cost*10/100
else:
final_cost=cost
'''
,please change this date, i took cyber monday.
'''
if date.today()==date(2020,11,30):
final_cost=final_cost+final_cost*5/100
'''
finally returning the calculated amount
'''
return final_cost
discount_cost1=compute_discount(150.78,True)
discount_cost2=compute_discount(98.23,False)
print("final discounted cost for 150.78 is "+str(round(discount_cost1,2)))
print("final discounted cost for 98.23 is "+str(round(discount_cost2,2)))
output
2) The second question is a part of first question we can give annotation and comment in our defined function as follows and can print that annotation in main, here is the code for printing annotation and comments(doc string) in that function. here is the code for that.
just modify the code above as follows,
from datetime import *
def compute_discount(cost:'float',ismember:'bool')->'float':
'''
Function defining here, Accepting two values from main , and calculate the discount based on the condition.
'''
if ismember==True:
final_cost=cost+cost*10/100
else:
final_cost=cost
'''
,please change this date, i took cyber monday.
'''
if date.today()==date(2020,11,30):
final_cost=final_cost+final_cost*5/100
'''
finally returning the calculated amount
'''
return final_cost
discount_cost1=compute_discount(150.78,True)
discount_cost2=compute_discount(98.23,False)
print("final discounted cost for 150.78 is "+str(round(discount_cost1,2)))
print("final discounted cost for 98.23 is "+str(round(discount_cost2,2)))
print(compute_discount.__doc__)
print(compute_discount.__annotations__)
output
Any doubt please comment, i am here to help you
Thanks in advance