Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Applied Computational Thinking with Python

You're reading from   Applied Computational Thinking with Python Algorithm design for complex real-world problems

Arrow left icon
Product type Paperback
Published in Dec 2023
Publisher Packt
ISBN-13 9781837632305
Length 438 pages
Edition 2nd Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Sofía De  Jesús Sofía De Jesús
Author Profile Icon Sofía De Jesús
Sofía De Jesús
 Martinez Martinez
Author Profile Icon Martinez
Martinez
Arrow right icon
View More author details
Toc

Table of Contents (25) Chapters Close

Preface 1. Part 1: An Introduction to Computational Thinking
2. Chapter 1: Fundamentals of Computer Science FREE CHAPTER 3. Chapter 2: Elements of Computational Thinking 4. Chapter 3: Understanding Algorithms and Algorithmic Thinking 5. Chapter 4: Understanding Logical Reasoning 6. Chapter 5: Errors 7. Chapter 6: Exploring Problem Analysis 8. Chapter 7: Designing Solutions and Solution Processes 9. Chapter 8: Identifying Challenges within Solutions 10. Part 2: Applying Python and Computational Thinking
11. Chapter 9: Introduction to Python 12. Chapter 10: Understanding Input and Output to Design a Solution Algorithm 13. Chapter 11: Control Flow 14. Chapter 12: Using Computational Thinking and Python in Simple Challenges 15. Chapter 13: Debugging 16. Part 3: Data Processing, Analysis, and Applications Using Computational Thinking and Python
17. Chapter 14: Using Python in Experimental and Data Analysis Problems 18. Chapter 15: Introduction to Machine Learning 19. Chapter 16: Using Computational Thinking and Python in Statistical Analysis 20. Chapter 17: Applied Computational Thinking Problems 21. Chapter 18: Advanced Applied Computational Thinking Problems 22. Chapter 19: Integrating Python with Amazon Web Services (AWS) 23. Index 24. Other Books You May Enjoy

Introduction to computer science

When looking for a definition of computer science, you will encounter multiple variations, but they all state that computer science encompasses all aspects of computers and computing concepts, including hardware and software. In computer science, hardware design is learned in courses offered in engineering or computer engineering, for the most part. The software side of computer science includes operating systems (OSs) and applications, among other programming areas. For this book, we will be concentrating on the software side of computer science.

In this chapter, we’ll look at some of the basic definitions, theories, and systems that are important as we delve deeper into the computational thinking world. Once we have identified key areas and defined the necessary concepts, we will be ready to move on to the applications and real-world challenges we face in an ever-changing tech world while also exploring the elements of computational thinking and the Python programming capabilities that can help us tackle these challenges.

The wide range of topics available in computer science can be both daunting and exciting and it is ever-evolving. Some of these topics include game design, OSs, applications for mobile or desktop devices, programming robots, and much more. Constant and consistent breakthroughs in computers and computing provide new and exciting opportunities, much of which is unknown to us. Having a basic understanding of the systems behind computer science can help us interact with technology and tackle problems more efficiently. Let’s start by learning about how computers store information using the binary system.

Learning about computers and the binary system

All computers store information as binary data. The binary system reads all information as a switch, which can be on or off – that is, 1 or 0. The binary system is a base-2 system. You’ll need a basic understanding of binary numbers and binary systems to progress in computer science.

The binary system translates all data so that it can be stored as strings using only two numbers: 0 and 1. Data is stored in computers using bits. A bit (which stands for binary digit) is the smallest unit of data you can find in a computer – that is, either a 0 or a 1.

When counting in the binary system, the first two numbers are 0 (or 00) and 1 (or 01), much like in the base-10 number system we use in everyday life. If we were to continue counting in binary, our next number would be 10. Let’s compare the first three numbers in the base-10 system and the binary system before we learn how to convert from one into the other:

Figure 1.1 – Base-10 and binary comparison

Figure 1.1 – Base-10 and binary comparison

The next number in the base-10 system would be 3. In the binary system, the next number would be 11, which is read as one one. The first 10 numbers in the base-10 and binary systems are as follows:

Base-10

Binary

0

00

1

01

2

10

3

11

4

100

5

101

6

110

7

111

8

1000

9

1001

10

1010

Figure 1.2 – Base-10 and binary comparison (continued)

As mentioned previously, the binary system is a base-2 system. This means that each digit of the base-10 system is paired with a power of 2, so we use those powers to convert between numbers. Understanding how to convert from base-2 into base-10 and vice versa can help us have a better understanding of the relationship between numbers in the different systems.

Converting from binary into base-10

We will start with an example of converting from a binary number into a base-10 number. Take the number 101101. To convert the number, each digit must be multiplied by the corresponding base-2 power. The binary number consists of 6 digits, so the powers of 2 we will use will be 5, 4, 3, 2, 1, and 0. This means the number is converted as follows:

1 × 2 5 + 0 × 2 4 + 1 × 2 3 + 1 × 2 2 + 0 × 2 1 + 1 × 2 0

= 32 + 0 + 8 + 4 + 0 + 1 = 45

The binary number 101101 is equivalent to 45 in the base-10 system. In everyday life, we write the numbers in base-10, so we understand the number 45 as it’s written. However, our computers convert this information into binary to be able to process it, so the number becomes the binary number 101101 so that it can easily be read by the computer.

Converting from base-10 into binary

Again, let’s start with an example to demonstrate the process of converting from a base-10 number into a binary number. Take the number 591. To convert the base-10 number into binary, we have to divide the number by 2 iteratively. If the result has no remainder, we insert a 0 (if it is the first number) or insert a 0 to the left of the existing numbers.

If the result has a remainder of 1, we insert a 1 (if it is the first number) or insert a 1 to the left of the existing numbers.

When we divide 591 by 2, the result is 295 with a remainder of 1. That means our right-most number, which is our first number, is 1.

Now, divide 295 by 2. The result is 147 with a remainder of 1. So, we insert a 1 to the left of the 1. Our number is now 11.

Now, divide 147 by 2. The result is 73 with a remainder of 1. Our result is now 111. Now, we’ll carry out further divisions:

  • 73 ÷ 2 = 36 with a remainder of 1. Our number is now 1111.
  • 36 ÷ 2 = 18 with no remainder. Our number is now 01111.
  • 18 ÷ 2 = 9 with no remainder. Our number is now 001111.
  • 9 ÷ 2 = 4 with a remainder of 1. Our number is now 1001111.
  • 4 ÷ 2 = 2 with no remainder. Our number is now 01001111.
  • 2 ÷ 2 = 1 with no remainder. Our number is now 001001111.
  • 1 ÷ 2 = 0 with a remainder of 1. Our number is now 1001001111.

The number 591 in base-10 is equivalent to the number 1001001111 in the binary system.

Another way to convert this number is to use a table for the divisions:

Starting Base-10

Divided by 2

Remainder

591

295

1

295

147

1

147

73

1

73

36

1

36

18

0

18

9

0

9

4

1

4

2

0

2

1

0

1

0

1

Table 1.1 – Converting base-10 number 591 into binary

Using this table, take the numbers from the right-most column and write them starting with the last row from bottom to top. The result is 1001001111.

Learning how to convert numbers is only a small part of converting data into binary, but it is an important one. All information, including letters and symbols, must be converted into binary to be read by a computer. American Standard Code for Information Exchange (ASCII) is a protocol that has been adopted universally to convert information. That said, some of the protocol is obsolete, so other protocols use ASCII as a base to expand their capabilities. UTF-16 is a widely used 16-bit character set that is based on Unicode, an extension of ASCII.

As discussed, in this section, we learned that information must be encoded or converted for a computer to read it. Multiple systems and protocols exist, but for now, we will move on to computer science theory. However, revisiting binary, ASCII, and Unicode as you work through problems can be helpful.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Applied Computational Thinking with Python
You have been reading a chapter from
Applied Computational Thinking with Python - Second Edition
Published in: Dec 2023
Publisher: Packt
ISBN-13: 9781837632305
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon