0
0
Pythonprogramming~15 mins

Lambda syntax and behavior in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Lambda syntax and behavior
๐Ÿ“– Scenario: Imagine you are helping a small shop calculate discounts on products quickly using simple functions.
๐ŸŽฏ Goal: You will create a lambda function to calculate discounted prices, then use it to find the discounted price of a product.
๐Ÿ“‹ What You'll Learn
Create a lambda function called discount that takes price and rate and returns the discounted price
Use the discount lambda function to calculate the price after a 20% discount on a product priced at 50
Print the discounted price
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Shops and businesses often use quick calculations like discounts to update prices fast.
๐Ÿ’ผ Career
Understanding lambda functions helps you write concise code for small tasks, useful in data processing and automation jobs.
Progress0 / 4 steps
1
Create a lambda function for discount calculation
Create a lambda function called discount that takes two parameters: price and rate. It should return the price after subtracting the discount (price minus price times rate).
Python
Need a hint?

Remember, a lambda function is written as lambda parameters: expression.

2
Set product price and discount rate
Create two variables: product_price set to 50 and discount_rate set to 0.2 (which means 20%).
Python
Need a hint?

Just assign the numbers 50 and 0.2 to the variables as shown.

3
Calculate discounted price using the lambda function
Create a variable called final_price and set it to the result of calling the discount lambda function with product_price and discount_rate as arguments.
Python
Need a hint?

Call the lambda function like a normal function with the two variables.

4
Print the discounted price
Write a print statement to display the value of final_price.
Python
Need a hint?

Use print(final_price) to show the discounted price.