KnowledgeBoat Logo
|

Computer Science

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

Python

Python Dictionaries

43 Likes

Answer

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}

Answered By

13 Likes


Related Questions