Programming Examples

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


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

Solution

emp_dic = { }
while True :
      name = input("Enter employee name : ")
      sal = int(input("Enter employee salary : "))
      emp_dic[ name] = sal
      choice = input("Do you want to Enter another record Press 'y' if yes : ")
      if choice != "y" :
            break
print(emp_dic)
▶ RUN

Output/ Explanation:

Enter employee name : amit

Enter employee salary : 4000

Do you want to Enter another record Press 'y' if yes : y

Enter employee name : sumit

Enter employee salary : 5000

Do you want to Enter another record Press 'y' if yes : y

Enter employee name : mohit

Enter employee salary : 4500

Do you want to Enter another record Press 'y' if yes : n

{'amit': 4000, 'sumit': 5000, 'mohit': 4500}

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad