Table of Contents

Create Dictionary Employee Names and Salaries

Example Description
This program allows you to input the number of employees, their names, and salaries, and then displays the data in a tabular format.

Introduction:

This Python program allows us to create a dictionary to store the names and salaries of employees. By inputting the number of employees, their names, and salaries, the program will display the data in a tabular format.

Code:

#Program to create a dictionary which stores names of the employee
#and their salary
num = int(input("Enter the number of employees whose data to be stored: "))
count = 1
employee = dict() #create an empty dictionary
while count <= num:
 name = input("Enter the name of the Employee: ")
 salary = int(input("Enter the salary: "))
 employee[name] = salary
 count += 1
print("\n\nEMPLOYEE_NAME\tSALARY")
for k in employee:
 print(k,'\t\t',employee[k])

Logic:

  1. Take input from the user for the number of employees.
  2. Create an empty dictionary called ’employee’.
  3. Use a while loop to iterate through each employee.
  4. Inside the loop, ask the user for the name and salary of each employee and store them in the dictionary.
  5. Increment the count variable.
  6. After the loop, display the data in a tabular format.

Output:

The program will display the names and salaries of the employees in a tabular format.

Enter the number of employees whose data to be stored: 3

Enter the name of the Employee: Ashish

Enter the salary: 20000

Enter the name of the Employee: Farman Ahmed

Enter the salary: 23000

Enter the name of the Employee: Maheshwari Peruri

Enter the salary: 22000

>>

>>

>> EMPLOYEE_NAME SALARY

>> Ashish 20000

>> Farman Ahmed 23000

>> Maheshwari Peruri 22000