29, జులై 2025, మంగళవారం

read employee data and print it python program.................................

 A program to read employee data from the keyboard and print that data can be implemented in various programming languages. The following example demonstrates this using Python, a widely used and beginner-friendly language.

Python
def get_employee_data():    """
    Reads employee data from the keyboard and returns it as a dictionary.
    """    employee_data = {}    employee_data['id'] = input("Enter Employee ID: ")    employee_data['name'] = input("Enter Employee Name: ")    employee_data['designation'] = input("Enter Employee Designation: ")    employee_data['salary'] = input("Enter Employee Salary: ")    return employee_datadef print_employee_data(data):    """
    Prints the provided employee data.
    """    print("\n--- Employee Details ---")    print(f"ID: {data['id']}")    print(f"Name: {data['name']}")    print(f"Designation: {data['designation']}")    print(f"Salary: {data['salary']}")if __name__ == "__main__":    employee_info = get_employee_data()    print_employee_data(employee_info)
Explanation:
  • get_employee_data() function:
    • This function prompts the user to enter employee details (ID, Name, Designation, Salary) using the input() function.
    • The entered data is stored in a dictionary called employee_data, where keys represent the data fields (e.g., 'id', 'name') and values are the user's input.
    • The function returns this employee_data dictionary.
  • print_employee_data(data) function:
    • This function takes a dictionary data (expected to be the employee_data dictionary) as an argument.
    • It then prints each piece of employee information in a formatted manner using f-strings for clear output.
  • if __name__ == "__main__": block:
    • This block ensures that the code inside it only runs when the script is executed directly (not when imported as a module).
    • It calls get_employee_data() to collect the employee information.
    • Finally, it calls print_employee_data() to display the collected information.

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి