In this python dictionary program, we will find the mean of values of keys in a dictionary.
Steps to solve the program
- Take a dictionary as input.
- Create two variables named total and count to find the mean of the values.
- Use for loop to iterate over values in the dictionary.
- Add the value to the total variable and 1 to the count variable.
- Find the mean by using the logic.
dict1 = {'m1':25,'m2':20,'m3':15}
total = 0
count = 0
for val in dict1.values():
total += val
count += 1
print("Mean: ",(total/count))
Output :
Mean: 20.0