In this python dictionary program, we will print the square of all values in a dictionary.
Steps to solve the program
- Take a dictionary as input.
- Use for loop to iterate over the dictionary.
- During iteration print the key and square of its value using **2.
- Print the output.
dictionary = {'a': 5, 'b':3, 'c': 6, 'd': 8}
for val in dictionary:
print(val,":", dictionary[val]**2)
Output :
a : 25
b : 9
c : 36
d : 64