in python, import operator employee={} for i in range(5): employeeId=int(input("Employee ID: ")) employeeName=in

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

in python, import operator employee={} for i in range(5): employeeId=int(input("Employee ID: ")) employeeName=in

Post by answerhappygod »

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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply