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)
Output

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}

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz