unit 3 lesson 4 Flashcards

(15 cards)

1
Q

Data Types & Variables

A

Would you store vegetables in your sock drawer and put your underwear in the freezer? Of course not! Everything has its ideal way of being stored, and saving data is no different. You may remember from math class that there are different types of numbers, including integers and real numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Integers

A

Integers can be positive or negative, but they cannot have a decimal point. For instance, if you divide 9 by 4, the answer expressed as an integer is 2, remainder 1, instead of 2.25. There can be no decimal place in integers!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Real Numbers

A

Numbers with a decimal place are called real numbers, or in the coding world, floating point numbers. An easy way to remember that term is to picture the decimal point floating around in its proper place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

variable

A

Data is stored in a variable, which is simply a reference to a reserved space on the computer’s memory drives. Often, different number types are given different variable types, so that they can be stored in different ways that are optimized for their unique structure and purpose. To use an analogy, think about a large parking lot. Every variable is a reserved car space in a parking lot, with some spaces shaped like integers, some like floating point numbers and some shaped like strings of text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Python & Data Types

A

However, for this course we don’t need to worry about that, because Python allows variables to hold any data type. That’s going to make things a little simpler for us!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Guided Example

A

In PythonAnywhere, let’s assign some data to a variable. In this example, we’ll set the value of the length variable to 5. Enter the following code into a file in PythonAnywhere.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Character Types

A

Alongside storing and processing of numbers, text is obviously a very popular data type. How is text stored in a variable?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Character Encoding

A

By now, you know that computers don’t actually store text! They only store and read binary code. Every file that you see stored in your computer’s filing system represents a stream of binary that has been encoded as a data type. Binary code representing audio is encoded as mp3, wav, and AAC files; binary representing video is encoded as MPEG3, and H264; and binary code representing images are encoded as BMP, JPEGs, and PNGS. Similarly, in order to store text, each text character is translated to binary code. This translation function is called encoding. Text to be interpreted by the computer is encoded as ASCII and Unicode, which are international standards that specify the binary code for any character in any human language. In this way, encoding allows for standardization across platforms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Structure Types

A

So that explains how individual characters of text are stored as data in the computer’s memory, but what about words, sentences, and more? Another data type, the structured data type, is devoted to combining individual data items and storing them as one variable. In the case of a word or sentence, a string variable would be used to store a combination of individual characters. This a perfect example of a structured data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Guided Example

A

Let’s assign a string of text to a variable, which in Python will automatically set this variable as a string data type. In this example, we’ll set the value of the welcome text variable to “Hello Fred! Thanks for coming!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Logical Types

A

One more kind of data used in Python is the logical type. This type represents values and variables that have only two possible values: true or false. Logical variables can be set directly to a value of true or false, or you can use conditions to set them dynamically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Input

A

Software needs new information to process, or it will simply give you the same outcomes every time you run it. Any time new information is supplied to your computer, it is receiving an input. In traditional computing, the inputs are probably typed text or mouse clicks. On a gaming console, controllers are the input device that gather inputs to allow a player to interact with the game. However, inputs don’t always come directly from a human. They might be data imported from another computer or database, or collected automatically as people use a product, such as how many attempts people are making before giving up.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Output

A

Once your program has processed the inputs, it has produced some information ready to be communicated to the outside world. This is called an output, and just like inputs they come in different shapes and sizes. Sometimes, the output may be a number, sometimes it may be a sentence, and sometimes it may be a whole reel of calculations about those changing weather patterns. In this unit, you’ve already seen the print statement, which prints output on the screen, and this is just the tip of the iceberg!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

GIGO

A

Garbage in, Garbage out is a common concept in mathematics and computer science. In short, it means that the output will be equal to the input. If the input is invalid, the output will be as well. Avoiding invalid inputs also helps programs to avoid errors that cause lags and crashes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

validate

A

To safeguard against this disastrous outcome, you should validate any inputted data to make sure it is in the correct format. In this case, you should check that there are no letters in the input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly