Back
Close

Python from Zero to Hero

toEpam
7,448 views

Exercise 1

Write a Python script to concatenate the following dictionaries to create a new one.

Example input 1:

dic1 = {1: 10, 2: 20}
dic2 = {3: 30, 4: 40}

Expected Result : {1: 10, 2: 20, 3: 30, 4: 40}

Example input 2:

dic1 = {1: 10, 2: 20}
dic2 = {3: 30, 4: 40}
dic3 = {5: 50, 6: 60}

Output : {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}

Merge dictionaries

Exercise 2

Write a Python script to generate and print a dictionary that contains a number (between 1 and n) in the form (x, x*x).

Example input 1:

n = 1

Expected Result : {1: 1}

Example input 2:

n = 5

Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

Merge dictionaries
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io