Exercise 4: Discount? Wow
In this exercise, you will be required to write a set function both with and without the set keyword.
We'll cover the following
Problem Statement
This exercise has two parts.
First Part
The shop decided to offer a 10% discount on Cheese
. In the first part, you are required to write a set function setPrice
which updates the price
after computing the discount.
Second Part
In the second part, you are required to implement the same functionality but this time you need to make the function using set
keyword instead. As an addition, you also need to call setPrice
in the testFunc
function given.
Note: We are using the
testFunc
function for testing purposes so no need to worry. Just call your function there.
Sample Input
20
Sample Output
18
Note: The skeleton function for
setPrice
is given in both the code tabs. Right now it is not being passed any parameters but you need to pass it appropriate parameter/parameters, use appropriate keywords and write the code for implementation as well.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy