Numbers Introduction

An introduction to the Numbers data type in Python

Numbers Introduction

In Python, like in all programming languages, data types are used to classify one particular type of data. This is important because the specific data type you use will determine what values you can assign to it and what you can do to it (including what operations you can perform on it).

Code examples will be shown in this style!!
Click code icon to see output…
Show Output
The output will be shown like this!!
Introduction

Any number you enter in Python will be interpreted as a number; you are not required to declare what kind of data type you are entering. Python will consider any number written without decimals as an integer (as in 138) and any number written with decimals as a float (as in 138.0).

Numbers

Like in math, integers in computer programming are whole numbers that can be positive, negative, or 0 (…, -1, 0, 1, …). An integer can also be known as an int. As with other programming languages, you should not use commas in numbers of four digits or more, so when you write 1,000 in your program, write it as 1000.

We can print out an integer in a simple way like this:

print(-25)
Show Output
-25

Or, we can declare a variable, which in this case is essentially a symbol of the number we are using or manipulating, like so:

my_int = -25
print(my_int)
Show Output
-25

We can do math with integers in Python, too:

int_ans = 116 - 68
print(int_ans)
Show Output
48

Integers can be used in many ways within Python programs, and as you continue to learn more about the language you will have a lot of opportunities to work with integers and understand more about this data type.

Integers

A floating-point number or a float is a real number, meaning that it can be either a rational or an irrational number. Because of this, floating-point numbers can be numbers that can contain a fractional part, such as 9.0 or -116.42. Simply speaking, for the purposes of thinking of a float in a Python program, it is a number that contains a decimal point.

Like we did with the integer, we can print out a floating-point number in a simple way like this:

print(17.3)
Show Output
17.3

We can also declare a variable that stands in for a float, like so:

my_flt = 17.3
print(my_flt)
Show Output
17.3

And, just like with integers, we can do math with floats in Python, too:

flt_ans = 564.0 + 365.24
print(flt_ans)
Show Output
929.24

With integers and floating-point numbers, it is important to keep in mind that 3 ≠ 3.0, as 3 refers to an integer while 3.0 refers to a float.

Floating Point Numbers (Float)(Real)

Write a program that demonstrates the use of both floats and integers.

Write a program that creates a variable for your age in years and then outputs it on the screen.

Write a program that has a variable for how much money you have with you today and adds it to a variable for how much money a friend has today. It should then output the total to the screen.

1.1 Numbers Introduction Task
Submit your completed task...
If you need to get in touch with Mr McG then this is the way….

What's your name?
image/svg+xml
Thank you [name], that's great.

Can I ask where you are from?
image/svg+xml
Hey [name], can I ask where you are from?
image/svg+xml
Hey [name], which class are you in?
image/svg+xml
OK [name], thanks for that.

I will need your email address so I can get back to you!!
image/svg+xml
Thanks [name], nearly there.

What can I help you with?
image/svg+xml

Thanks [name] from [whichclass][location], Mr McG will get your message…"
[message]"…and will get back to you ASAP via [email]. Catch you soon.

image/svg+xml
Thank you [name], Mr McG got your message.
Thanks [name], Mr McG will get back to you as soon as he can!!

Have a great day!!

K McGuinness - 2018

No personal data will be shared with any third party. The only data processed via this website is anonymous browsing data to best manage your user experience.