Computer Science
Write a program to enter names of employees and their salaries as input and store them in a dictionary.
Python
Python Dictionaries
43 Likes
Answer
d = {}
ans = "y"
while ans == "y" or ans == "Y" :
name = input("Enter employee name: ")
sal = float(input("Enter employee salary: "))
d[name] = sal
ans = input("Do you want to enter more employee names? (y/n)")
print(d)
Output
Enter employee name: Kavita
Enter employee salary: 35250.50
Do you want to enter more employee names? (y/n)y
Enter employee name: Rakesh
Enter employee salary: 27000
Do you want to enter more employee names? (y/n)n
{'Kavita': 35250.5, 'Rakesh': 27000.0}
Answered By
13 Likes
Related Questions
Predict the output :
dct = {} dct[1] = 1 dct ['1'] = 2 dct[1.0] = 4 sum = 0 for k in dct: print(k, sum) sum += dct[k] print(sum)
Fill in the blanks of the following code so that the values and keys of dictionary d are inverted to create dictionary fd.
d = {'a':1, 'b':2, 'c':3} print(d) fd = {} for key, value in d.____(): fd[____] = ____ print(fd)
Write a program to count the number of times a character appears in a given string.
Write a program 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'.
(Hint. use dictionary for keys 0-9 and their values as equivalent words.)