CBSE Class 11 Computer Science Question 101 of 112

Dictionaries — Question 1

Back to all questions
1
Question

Question 1

Write a program to enter names of employees and their salaries as input and store them in a dictionary.

Solution
d = {}
ans = "y"
while ans == "y" or ans == "Y" :
      name = input("Enter employee name: ")
      sal = float(input("Enter employee salary: "))
      d[name] = sal
      ans = input("Do you want to enter more employee names? (y/n)")    
print(d)
Output
Enter employee name: Kavita
Enter employee salary: 35250.50
Do you want to enter more employee names? (y/n)y
Enter employee name: Rakesh
Enter employee salary: 27000
Do you want to enter more employee names? (y/n)n
{'Kavita': 35250.5, 'Rakesh': 27000.0}
Answer