Python Program — Display Salaries Less Than 25000 Using a Function
Write a function Show_sal(EMP) in python that takes the dictionary, EMP as an argument. Display the salary if it is less than 25000. Consider the following dictionary
EMP = {1 : 18000, 2 : 25000, 3 : 28000, 4 : 15000}
The output should be:
18000
15000
In this program, we create a Python function Show_sal(EMP) that accepts a dictionary of employee salaries (EMP) and displays all salaries that are less than 25,000.
This program is important for Class 12 Computer Science (Python Functions & Dictionaries) and helps students understand dictionary traversal and conditional statements in functions.
🔹 Problem Statement
Write a Python function Show_sal(EMP) that takes a dictionary EMP as an argument and displays salaries less than 25,000.
Example Dictionary:
EMP = {1: 18000, 2: 25000, 3: 28000, 4: 15000}
Expected Output:
18000
15000
✅ Python Program
def Show_sal(EMP):
for emp_id in EMP:
salary = EMP[emp_id]
if salary < 25000:
print(salary)
# ---- Function Call ----
EMP = {1: 18000, 2: 25000, 3: 28000, 4: 15000}
Show_sal(EMP)
📝 Explanation
- The function
Show_sal(EMP)accepts a dictionary of employee salaries. for emp_id in EMP:loops through all employee IDs in the dictionary.- Each salary is checked:
if salary < 25000: - If the condition is true, the salary is printed.
This program demonstrates dictionary traversal, conditional logic, and functions in Python.
🖥 Sample Output
18000
15000
🎯 Learning Outcomes
- How to define and call a Python function
- Traversing dictionary values
- Using conditional statements inside a function
- Filtering data based on a numeric condition
It is an important CBSE Class 12 Python function program frequently asked in exams and practical files.
In every board examination cbse must asked the programming questions based on CBSE Class 12 Functions, File Handling, Stack and Python MySQL connectivity Questions