Python Exercise Lists

Python Condition Statement Exercises

1. Write a python program to get one word input from the user and then reverse it as another output. The following output can show one of the example

The output is:

Please input a word to reverse it: python

Expected Answer:
nohtyp

Click for the answer



2. Write a python program to convert the temperature either from celsius to fahrenheit or from fahrenheit to celsius. To request the program user to input the temperature value with their F or C to represent fahrenheit or celsius. One of the example is shown below.

The output is:

Please input the temperature for convertion (e.g:101C, 30F): 40C

Expected Answer:
The temperature in Fahrenheit is 104 degrees.

Click for the answer



3. Write a python program to calculate the number of even and odd numbers from a

The output is:

Please input the temperature for convert (e.g:101C, 30F): 40C

Expected Answer:
The temperature in Fahrenheit is 104 degrees.

Click for the answer



4. Write a python program to guess a number between 1 to 10. When guessing correctly, pop out a message to inform the user. One of the example can be seen in the following output:

One of the example output is:

Expected Answer:
Guess a number between 1 and 10 until you get it right : 5
Guess a number between 1 and 10 until you get it right : 6
Guess a number between 1 and 10 until you get it right : 7
Guess a number between 1 and 10 until you get it right : 8
Guess a number between 1 and 10 until you get it right : 9
Guess a number between 1 and 10 until you get it right : 10
Congratulations, you guess correctly!

Click for the answer



5. Write a python program to identify all the numbers which are divisible by 8 in between 200 and 500.

One of the example output is:

Expected Answer:
200,208,216,224,232,240,248,256,264,272,280,288,296,304,312,320,328,336,344,352,360, 368,376,384,392,400,408,416,424,432,440,448,456,464,472,480,488,496

Click for the answer



6. Write a python program to all the items in a list_a as shown in the output below with their corresponding class of the items

The output is:

list_a = [1868, 2+5j, True, 'freelearningpoints', 1.52, {"Python user":123}, (2, -9), [6, 18]]

Expected Answer:
The class of 1868 is [class 'int'
The class of (2+5j) is [class 'complex']
The class of True is [class 'bool']
The class of freelearningpoints is [class 'str']
The class of 1.52 is [class 'float']
The class of {'Python user': 123} is [class 'dict']
The class of (2, -9) is [class 'tuple']
The class of [6, 18] is [class 'list']

Click for the answer



7. Write a python program to iterate the numbers from 1 to 20. All the numbers which able to be multiplied by 3 replaced with 'Bee' and the numbers which able to be multiplied by 5 replaced with 'Jee'.

The output is:

Expected Answer:
Bee
0
1
2
Bee
3
4
Jee
5
Bee
6
7
8
Bee
9
Jee
10
11
Bee
12
13
14
Bee
15
16
17
Bee
18
19
Jee
20

Click for the answer



8. Write a python program to print all the numbers from 1 to 20 except even number. Note that continue is an important statement to be used in this case.

The output is:

Expected Answer:
1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

Click for the answer



9. Write a python program to request user to input the number of rows and columns therefore create a two-dimensional array. One of the example in the output below.

The output is:

Expected Sample Answer:
Please input the columns number: 3
Please input the rows number: 4
[[0, 0, 0], [0, 1, 2], [0, 2, 4], [0, 3, 6]]

Click for the answer



10. Write a python program to request user to input a word then calculate then number of input letter. One of the example in the output below.

The output is:

Expected Sample Answer:
Please input a word: python
Letters 6

Click for the answer



11. Write a python program to check the input number is an odd number or even number?

The output is:

Expected Sample Answer:
Enter a number: 5
This is an odd number.

Click for the answer



12. Write a python program to print out all the add numbers and only stop the printing immediately for the remaining numbers come after 88 based on the list_a provided in the following output

The output is:

numbers = [23, 66, 98, 56, 45, 78, 33, 52, 14, 65, 79, 90, 8, 35, 58, 60, 32, 48, 36, 68, 24, 80, 56, 78, 35, 88, 24, 56, 79, 43, 67, 32, 78, 43, 79, 66, 54, 78, 35, 78, 56, 89, 43, 67, 89, 43, 78, 98, 12, 61, 29, 35, 82, 49, 73, 56, 37 ]

Expected Sample Answer:
23
45
33
65
79
35
35
88

Click for the answer



13. Write two python program to print out the 5 symbols of "$" without newline and another 5 symbols of "@" in newline

The output is:

Expected Sample Answer 1:
$$$$$

Expected Sample Answer 2:
@
@
@
@
@

Click for the answer



14. Write a python program to list out all the python modules which have installed in your local computer or laptop.

The output is:

Expected Sample Answer 1:
jupyter-client==5.3.1
jupyter-console==6.0.0
jupyter-core==4.5.0
jupyter==1.0.0
jupyterlab-server==1.0.0
jupyterlab==1.0.2

Click for the answer



15. Write a python program to identify the median number among three randomly input numbers from user.

The output is:

Expected Sample Answer:
Please input the first number: 3
Please input the second number: 9
Please input the third number: 1
The median number of the above three numbers is 3

Click for the answer



16. Write a python program to help the teacher to sum up the exam paper of part I and part II after that print out the result whether pass or fail. (Passing mark: 60)

The output is:

Expected Sample Answer 1:
Please input machine learning Part I marks:
30
Please input machine learning Part II marks:
45
Congratulation, Pass!

Expected Sample Answer 2:
Please input machine learning Part I marks:
10
Please input machine learning Part II marks:
12
Fail!

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