Programs · Program 10-6
Q.Program 10-6: Write a program to enter names of employees and their salaries as input and store them in a dictionary.
Tamil Nadu DgeTextbookSubjective· 3mImportance★★★★★est
33% · 10/30 Questions
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 →A counted input loop fills the dictionary with employees[name] = salary, then an iteration prints each stored pair — names as keys, salaries as values.
The idea. Growing a dictionary from user input is a single idiom: assignment to a new key inserts a pair. The employee's name is the natural key (what we look records up by) and the salary is the value. range(num) runs the input loop exactly the requested number of times.
Program 10-6:
num = int(input("Enter the number of employees: "))
employees = {}
for count in range(num):
name = input("Enter the name of the employee: ")
salary = int(input("Enter the salary: "))
employees[name] = salary
print()
print("Employee name and salary:")
for name in employees:
print(name, ":", employees[name])
Sample run:
Enter the number of employees: 3
Enter the name of the employee: Tara
Enter the salary: 45000
Enter the name of the employee: John
Enter the salary: 52000
Enter the name of the employee: Farhan
Enter the salary: 48000
Employee name and salary:
Tara : 45000
John : 52000
Farhan : 48000
Key lines:
employees[name] = salary— insertion by assignment; the dictionary needs no pre-sizing. …
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.