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...
In PYTHON Write an algorithm for a function called removeAll which takes 3 parameters: an array...
In PYTHON Write an algorithm for a function called removeAll which takes 3 parameters: an array of array type, a count of elements in the array, and a value. As with the remove method we discussed in class, elements passed the count of elements are stored as None. This function should remove all occurrences of value and then shift the remaining data down. The last populated element in the array should then be set to None. The function then returns...
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 1) Pig Latin Write a function called igpay(word) that takes in a string word...
IN PYTHON 1) Pig Latin Write a function called igpay(word) that takes in a string word representing a word in English, and returns the word translated into Pig Latin. Pig Latin is a “language” in which English words are translated according to the following rules: For any word that begins with one or more consonants: move the consonants to the end of the word and append the string ‘ay’. For all other words, append the string ‘way’ to the end....
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters,...
This is an intro to python question. #Write a function called search_for_string() that takes two #parameters, a list of strings, and a string. This function #should return a list of all the indices at which the #string is found within the list. # #You may assume that you do not need to search inside the #items in the list; for examples: # # search_for_string(["bob", "burgers", "tina", "bob"], "bob") # -> [0,3] # search_for_string(["bob", "burgers", "tina", "bob"], "bae") # -> []...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the...
In Python: Write a function called sum_odd that takes two parameters, then calculates and returns the sum of the odd numbers between the two given integers. The sum should include the two given integers if they are odd. You can assume the arguments will always be positive integers, and the first smaller than or equal to the second. To get full credit on this problem, you must define at least 1 function, use at least 1 loop, and use at...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the...
Write a Python function ???????? that takes in a nonnegative semiprime number ? which is the product of two prime numbers ? and ? and returns the tuple ( ?, ? ) where ?≤? . Example: ????????(22)=(2,11) Example: ????????(3605282209)=(59447,60647) This problem has a time-out limit of 1 second and a memory limit of 1MB. The number ? in all test-cases will satisfy 4≤?≤800000000000000 For example: Test Result print(factorMe(22)) (2, 11) print(factorMe(3605282209)) (59447, 60647)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT