Popular Posts

Saturday, August 15, 2020

Python Beginner: Working with Numbers

 Hello, developer!

Are you familiar with functions? A function is useful way to reuse codes and reduce the effort to develop the same codes. Don't worry even if you don't fully understand the concept of functions. You will learn more & more about it proceeding this course! :)

Let's learn several methods of conversion numbers. We will use the numbers type variables and math functions in the exercise program.

Internal Math functions

- abs(number): Convert minus number into plus number(i.e.: abs(

- str(number): Convert numbers type into strings type

- pow(number1, number2): number1 multiply number1 until number2 times

- max(number1, number2): Compare two numbers and show a bigger number

- min(number1, number2): Compare two numbers and show a smaller number

- round(number): Round down or up of a number(i.e.: round(3.2) > 3, round(3.7) > 4)

Python supports importing external modules so developers can easily use external functions. In this program, we will import the math module for using more math functions. Here is the math module importing command. 

from math import *

I showed the math module functions with purpose and examples.

External Math module functions

- floor(number): Return closet smaller integer value from input decimal(i.e.: floor(4.2) > 4)

- ceil(number): Return closet bigger integer value from input decimal(i.e.: ceil(4.2) > 5)

- sqrt(number): Return square value from input decimal(i.e.: sqrt(36) > 6.0)

I input the below codes and confirmed results like the following screenshot.

from math import *
my_num = 5
my_num2 = -5
print(10 % 3) # remainder
print(10 /3)
print(str(my_num) + " my favorite number.")


Have you seen the same result on the console window? If yes, congratulations! Now you can import external modules for extended math functions and use math functions as well.

If you are interested in the math functions, please refer below link for your reference. 


I encourage you to refer to the Python Document References. You can search for functions that you want to use in your program and use searched functions in your codes. These efforts will lead you to understand Python coding and develop codes effectively.

Alright! See you next in the next post, developer! :)


No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...