Program Code
Program Code
DICTIONARY
1. Create a dictionary ‘ODD’ of odd numbers between 1 and 10, where the key is the decimal
number and the value is the corresponding number in words. Perform the following operations on
this dictionary:
(h) Delete the item from the dictionary corresponding to the key 9
Ans:
# (h) Delete the item from the dictionary corresponding to the key 9
ODD.pop(9, None)
print("Dictionary after deleting key 9:", ODD)
# Output: Dictionary after deleting key 9: {1: 'one', 3: 'three', 5: 'five', 7: 'seven'}
2. Write a program to enter names of employees and their salaries as input and store them
in a dictionary.
Ans.
program code:
# Number of employees
num_employees = int(input("Enter the number of employees: "))
Executable output:
3. Write a program to count the number of times a character appears in a given string.
Ans:
Program Code:
Executable Output:
4. Write a function to convert a number entered by the user into its corresponding number
in words. For example, if the input is 876 then the output should be ‘Eight Seven Six’.
Ans:
Program Code:
Executable Output:
OR
Enter a number: 7890
The number in words is: Seven Eight Nine Zero
5. Write a program to display the name of all the employees whose salary is more than
25000 from the following dictionary.
emp={1:(“Amit”,25000),2:(“Suman”,30000),3:(“Ravi”,36000)}
Format of data is given below :{Empid : (Empname, EmpSalary)}
Ans:
Program Code:
# Employee dictionary
emp = {1: ("Amit", 25000), 2: ("Suman", 30000), 3: ("Ravi", 36000)}
# Get the list of employees with salary more than the threshold
result = display_high_salary_employees(emp, threshold)
Output: