in python,
import operatoremployee={}for i in range(5): employeeId=int(input("Employee ID: ")) employeeName=input("Employee name: ") employee[employeeId]=employeeNameprint(employee)sortedEmployee = sorted(employee.items(),key=operator.itemgetter(1))print("In ascending order: ",sortedEmployee)***add to the above code:Start a While loop and ask the user to enter a new key and employeename, to add to the dictionary.From within the While loop, check if the key already exists and ifit exists, display a message indicating the Key already exists;otherwise, proceed to add the new id and key to the dictionary. Ifthe user enters an id of -1 break from the While loop
in python, import operator employee={} for i in range(5): employeeId=int(input("Employee ID: ")) employeeName=in
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am