Print the square of all values in a dictionary.

In this python dictionary program, we will print the square of all values in a dictionary.

Steps to solve the program
  1. Take a dictionary as input.
  2. Use for loop to iterate over the dictionary.
  3. During iteration print the key and square of its value using **2.
  4. 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
				
			

add elements to the dictionary.

move items from dict1 to dict2.

Leave a Comment