DS T04 - Numerical Data Types
DS T04 - Numerical Data Types
Remember that with our courses, you’re not alone! You can contact an expert code
reviewer to get support on any aspect of your course.
Our team is happy to offer you support that is tailored to your individual career or
education needs. Do not hesitate to ask a question or for additional support!
Software development is full of acronyms. Here’s a link to the Hyperion Hub where you will
find some frequently used software development terms you’d do well to be familiar with,
for when it’s next thrown your way.
Whether you are fond of math or not, you cannot escape numbers. Numbers play
an extremely important role in our daily lives. Probably not a day goes by without
you interacting with numbers in some way. Think about it. Did you go shopping
today and look at the prices of items? Did you change the volume or channel on
your TV? Did you drive anywhere today and notice the speed limit signs or
instrumentation on your vehicle's dashboard? Have you made a telephone call
today? Chances are you have done at least one of these things and if you haven't,
you can probably think of numerous other instances where you have encountered
numbers today.
You have also probably learned from school math that there are different types of
numbers. For example, whole numbers and decimal numbers. Whole numbers do
not contain a fractional part and can be used to count the items in a list. However,
decimal numbers do contain a fractional part. Decimal numbers are normally used
when precision is required, such as when dealing with measurements or currency.
With numbers being so important in our daily lives, it comes as no surprise that
they are equally important in programming. Every single programming language
provides support for manipulating, storing and defining different types of
numbers.
NUMBERS IN PYTHON
● Integers: these are synonymous with whole numbers. Numbers which are
stored as this type do not contain a fractional part or decimal. Integers can
either be positive or negative and are normally used for counting or simple
calculations. For example, you can store the number of items you wish to
purchase from a store as an integer, e.g. num = int("-12").
● Complex: complex numbers have a real and imaginary part, which are each
a floating-point number, e.g. c = complex("45.j").
class_list = 25 # integer
interest_rate = 12.23 # float
To cast between numbers, make use of the int() or float() functions, depending on
which is needed.
num1 = 12
num2 = 99.99
print(float(num1))
# Converting floats to ints, as below, causes data loss. int() removes values
# after the decimal point, returning only a whole number.
print(int(num2))
ARITHMETIC OPERATIONS
Doing calculations with numbers in Python works similarly to the way they would
in normal math.
sum = 2 + 4
print(sum)
# prints out 6
MATHEMATICAL FUNCTIONS
Python also has a library of pre-written code that you can access and use in your
code. The math module contains many mathematical functions. Some of the most
commonly used functions are listed in the table below:
Function Description Example
Explore some more functions in the math module here. To be able to use the
functions in the math module, add this line of code to the top of your program:
import math
The further you progress on your Python journey, the more complex the programs you
build will become. Here are the top 5 Python libraries that you could use to create these
complex programs. It helps to be aware of them and know what they do so that you can
call on them when needed and as you gain more experience.
● PyGame. A cross-platform set of Python modules for creating video games and
multimedia programs. It is highly portable and runs on nearly every platform and
operating system.
● Scrappy. An open-source and collaborative framework for extracting the data you
need from websites. In a fast, simple, yet extensible way.
● Apache Libcloud. A library interacting with many of the popular cloud service
providers using a unified API. It was created to make it easy for developers to build
products and work between any of the services that it supports.
Instructions
Before you get started, we strongly suggest you use an editor such as VS Code or
Anaconda to open all text files (.txt) and python files (.py).
● example.py should help you understand some simple Python. Every task
will have example code to help you get started. Make sure you read all of
example.py and try your best to understand.
● You may run example.py to see the output. Feel free to write and run your
own example code before doing the Task to become more comfortable with
Python.
Compulsory Task 1
If you are having any difficulties, please feel free to contact our specialist team on
Discord for support.
1. Make sure that you have installed and set up all programs correctly. You have set
up Dropbox correctly if you are reading this, but Python or your editor may not
be installed correctly.
2. If you are not using Windows, please ask a reviewer for alternative instructions.
Hyperion strives to provide internationally-excellent course content that helps you achieve
your learning outcomes.
Think that the content of this task, or this course as a whole, can be improved, or think
we’ve done a good job?