Question

In: Computer Science

'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a...

'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.

Solutions

Expert Solution

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


Related Solutions

Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints...
Write a Python function that takes as input parameters base_cost (a float) and customer_type and prints a message with information about the total amount owed and how much the tip was. As a reminder, the tip amounts are 10%, 15% and 20% for stingy, regular, and generous customers. And the tax amount should be 7%. The total amount is calculated as the sum of two amounts: check_amount = base_cost*1.07 tip_amount = tip_percentage*check_amount To receive full credit, you must use string...
Python Programming 1. Write a function name split_name which takes one parameter called name. If the...
Python Programming 1. Write a function name split_name which takes one parameter called name. If the name parameter value is a name in the form LastName, FirstName(e.g., ”Grounds, Nic”) then the function should return a list of two elements where FirstName is the first element and LastName is the second element. If the name parameter value is a name in the form FirstName LastName(e.g., ”Nic Grounds”) then the function should return a list of two elements where FirstName is the...
Write a python function image compress() that takes one argument called filename, which is the name...
Write a python function image compress() that takes one argument called filename, which is the name of a file that contains a N × N (N-pixel by N-pixel) “grayscale bitmap image”. A “grayscale bitmap image” is an image of the following form where every pixel contains a grayscale color value between 0 − 255 (inclusive). Colour value 0 means that pixel should appear completely black and color value 255means completely white. Any other value in between stands for different shades...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and...
Write a recursive function in python called make_palindrome that takes a sequence as a parameter and returns a new sequence that is twice the length of the parameter sequence but that contains the contents of the original in palindrome form. For example, if the sequence "super" is passed into the function, the function will return "superrepus".
In python of Jupiter notebook Write a python function called trng that takes three numbers x,...
In python of Jupiter notebook Write a python function called trng that takes three numbers x, y, and z, and specifies if those can form a triangle (i.e., returns the word triangle if they can, and Not a triangleotherwise). Note: In order for three numbers to form a triangle sum of any two of them must be greater than the third one (e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not greater than z even though x+z>y...
In python Define a function called cfb_graph which takes no arguments. Form a directed graph from...
In python Define a function called cfb_graph which takes no arguments. Form a directed graph from the file cfb2010.csv by considering the teams as vertices and creating an edge between team1 and team2 only if team1 defeated team2. You should familiarize yourself with this file before attempting this part. cfb_graph will return a dictionary giving this representation.
1.1 Write a python in Jupiter notebook function called trng that takes three numbers x, y,...
1.1 Write a python in Jupiter notebook function called trng that takes three numbers x, y, and z, and specifies if those can form a triangle (i.e., returns the word triangle if they can, and Not a triangle otherwise). Note: In order for three numbers to form a triangle sum of any two of them must be greater than the third one (e.g., x=1, y=2, z=4 cannot form a triangle because x+y is not greater than z even though x+z>y...
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output...
Write a function (in Javascript) called longestMorseCodeWords which takes in an array of strings. The output of longestMorseCodeWords should be an array of the strings that were passed in, but ordered by the length of their Morse Code equivalent in descending order. If the length of Morse Code is equal, order the words alphabetically.For convenience, the full table for the 26 letters of the English alphabet is given below: [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] let words = ["gin", "zen", "gig", "msg"] longestMorseCodeWords(words) The Morse...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should...
PYTHON: Write a function insertInOrder that takes in a list and a number. This function should assume that the list is already in ascending order. The function should insert the number into the correct position of the list so that the list stays in ascending order. It should modify the list, not build a new list. It does not need to return the list, because it is modifying it.   Hint: Use a whlie loop and list methods lst = [1,3,5,7]...
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT