Python Exercise Lists

Python Library Exercises

1. Write a python program to add on the following dictionaries, dict_a, dict_b and dict_c to be a new dictionary, dict_d.

The output is:

dict_a={1:"Python", 2:"Is", 3:"Programming"}
dict_b={4:"Language", 5:"the", 6:"most"}
dict_c={7:"popular",8:"free", 9:"exercises"}

Expected Answer:
The new dict_d: {1: 'Python', 2: 'Is', 3: 'Programming', 4: 'Language', 5: 'the', 6: 'most', 7: 'popular', 8: 'free', 9: 'exercises'}

Click for the answer



2. Write a python program to change the symbol between dictionary key and dictionary value, dict_a is provided in the following output. Note that the for loop is expected to be used for this exercise.

The output is:

dict_a={1:"Python", 2:"Is", 3:"Programming", 4:"Language", 5:"the", 6:"most"}

Expected Answer:
1 >>>>> Python
2 >>>>> Is
3 >>>>> Programming
4 >>>>> Language
5 >>>>> the
6 >>>>> most

Click for the answer



3. Write a python program to input a number as keys in dictionary, therefore generate the key number starting from 1 until the "input number" with dictionary values are square of corresponding key number which are provided in the following output. Note that the for loop is expected to be used for this exercise.

The output is:

Example 1:
Please input a lucky number: 8

Expected Answer:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}

Example 2:
Please input a lucky number: 6

Expected Answer:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36}

Click for the answer



4. Write a python program where the key value in a dictionary are between 3 and 20, and dictionary values are square of corresponding key number which are provided in the following output. Note that the for loop is expected to be used for this exercise.

The output is:

Expected Answer:
{3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 225, 16: 256, 17: 289, 18: 324, 19: 361, 20: 400}

Click for the answer



5. Write a python program to combine two separate Python dictionary, dict_a and dict_b as one Python dictionary.

The output is:

dict_a={1:"Python", 2:"Is", 3:"Programming", 4:"Language", 5:"the"}
dict_b={6:"most", 7:"popular",8:"free", 9:"exercises"}

Expected Answer:
{1: 'Python', 2: 'Is', 3: 'Programming', 4: 'Language', 5: 'the', 6: 'most', 7: 'popular', 8: 'free', 9: 'exercises'}

Click for the answer



6. Write a python program to sum up all the values in a Python dictionary, dict_a as a Python dictionary showed in the following output.

The output is:

dict_a = {'Python_user': 2357, 'R-Programming_user':1988, 'Java_user':597}

Expected Answer:
The sum of programmer in town A is 4942

Click for the answer



7. Write a python program to muliply all the values in a Python dictionary, dict_a as a Python dictionary showed in the following output.

The output is:

dict_a = {'Python_user': 2357, 'Python_download_times':1988}

Expected Answer:
The total download number of Python Installation time is 4685716

Click for the answer



8. Write a python program to remove a key value "2" from a Python dictionary, dict_a as a Python dictionary showed in the following output.

The output is:

dict_a={1:"Python", 2:"Is", 3:"Programming", 4:"Language", 5:"the", 6:"most"}

Expected Answer:
{1: 'Python', 2: 'Is', 3: 'Programming', 4: 'Language', 5: 'the', 6: 'most'}
{1: 'Python', 3: 'Programming', 4: 'Language', 5: 'the', 6: 'most'}

Click for the answer



9. Write a python program to combine two lists into a Python dictionary, list_a and list_b as a Python list showed in the following output.

The output is:

list_a = [1, 2, 3, 4, 5, 6]
list_b = ['Python', 'Is', 'Programming', 'Language', 'the', 'most']

Expected Answer:
{1: 'Python', 2: 'Is', 3: 'Programming', 4: 'Language', 5: 'the', 6: 'most'}

Click for the answer



10. Write a python program to list out the maximum and minimum value from a Python dictionary, list_a as a Python list showed in the following output.

The output is:

dict_a = {'Python user': 2357, 'R-Programming user':1988, 'Java user':597, 'C Programming user':5670}

Expected Answer:
The maximum value is: 5670
The minimum value is: 597

Click for the answer



                               


More Exercises:

Python String Exercises
Python List Exercises
Python Library Exercises
Python Sets Exercises
Python Array Exercises
Python Condition Statement Exercises
Python Lambda Exercises
Python Function Exercises
Python File Input Output Exercises
Python Tkinter Exercises


More Numpy Exercises:

Numpy String Exercises
Numpy Integer Exercises
Numpy Array Exercises
Numpy Data Analysis Exercises
Numpy Data Sorting Exercises


More Pandas Exercises:

Pandas Series Exercises


More Tutorials:

Python Installation - Linux (Ubuntu)
Python Installation - Mac OS
Integrated Development Environment - IDE
Python - Basic Variables
Python - Sequence Introduction
Python - Output Formatting
Python - Escape Character
Python - Type Conversion
Python - Numbers
Python – Arithmetic Operators
Python – Assignment Operators
Python – Comparison Operators
Python – Logical Operators
Python – Precedence and Associativity Operators
Python – Bytes Type and Usage
Python – Long & Raw Strings
Python – Concatenate Function
Python – Slice Function
Python – Length and Split Function
Python – Join and Count Function
Python – Find Function
Python – Index Function
Python – Alignment Function
Python – Startswith and Endswith Function
Python – String Case Conversion
Python – Remove Specified Character
Python – Encode and Decode Function
Python – dir and help Function
Python – Input Output Introduction
Python – Basic Operation
Python – Open Function
Python – Read Function
Python – Readline Function
Python – Write Function
Python – Close Function
Python – Seek and Tell Function
Python – Pickle Module
Python - File Input Module and Linecache Module
Python - Pathlib Module
Python - Pathlib Module
Python - os.path Module
Python - fnmatch Module
Python - Tuple Introduction
Python - List Introduction
Python - List Add Element
Python - List Delete Element
Python - List Modification Element
Python - List Find Element
Python - Dictionary Introduction
Python - Dictionary Basic Operation
Python - Dictionary Method Guide
Python - Set Collection
Python - Set Basic Operation
Python - Set Basic Method
Python - Frozenset Method
Python - If Condition I
Python - If Condition II
Python - While loop
Python - For loop
Python - Pass Statement
Python - Break Statement
Python - Zip Reverse Function
Python - Function Introduction
Python - Positional Parameters
Python - Key Arguments
Python - None and Return
Python - Variable Scope
Python - Local Function
Python - Closure Method
Python - Lamdba Expression