Skip to content
Programs · Program 4-4

Q.Write a program to enter names of employees and their salaries as input and store them in a dictionary. Here n is to input by the user.

Telangana TsbieTextbookSubjective· 3mImportance★★★★★est
20% · 6/30 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Read n employees' names and salaries, storing them in a dictionary, then print a name/salary table.

n = int(input("Enter the number of employees to be stored: "))
empDict = {}
for i in range(n):
    name = input("Enter the name of the Employee: ")
    salary = int(input("Enter the salary: "))
    empDict[name] = salary

print("EMPLOYEE_NAME", "  SALARY")
for name in empDict:
    print(name, " ", empDict[name])

Output:

Enter the number of employees to be stored: 5
Enter the name of the Employee: 'Tarun'  Enter the salary: 12000
Enter the name of the Employee: 'Amina'  Enter the salary: 34000
Enter the name of the Employee: 'Joseph'  Enter the salary: 24000
Enter the name of the Employee: 'Rahul'  Enter the salary: 30000 …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.