In: Computer Science
-Python-
Suppose Dict = {1: ["Jack", 35, 13.00], 20:["James", 20, 8.50], 14:["Jordan", 38, 12.00], 12:["Wayne", 33, 12.00]}
1. Print name and grosspay(hours * pay) of each person in a new line.
2. Print average of hours
Explanation:
Here is the code which has the Dictionary given.
In the first part, it prints the name and the gross pay of each person mentioned in the dictionary by traversing the values of the dictionary.
In the second part, all the hours are added and the persons are counted to calculate the average hours.
Code:
Dict = {1: ["Jack", 35, 13.00], 20:["James", 20, 8.50],
14:["Jordan", 38, 12.00], 12:["Wayne", 33, 12.00]}
#Part 1:
for k, v in Dict.items():
print(v[0], v[1]*v[2])
#Part 2:
avg = 0
n = 0
for k, v in Dict.items():
avg = avg + v[1]
n = n + 1
avg = avg/n
print("Average hours:", avg)
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!