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:
- Take input from the user for the number of employees.
- Create an empty dictionary called ’employee’.
- Use a while loop to iterate through each employee.
- Inside the loop, ask the user for the name and salary of each employee and store them in the dictionary.
- Increment the count variable.
- 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