What is Programming? Flashcards

1
Q

Central Processing Unit

A
  • the part of the computer obsessed with “what is next?”

- if computer is rated at 3.0 gigahertz, it means the cpu asks what’s next three billion times per second

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

Main Memory

A
  • used to store information the CPU needs in a hurry
  • nearly as fast as CPU
  • info stored in main memory vanishes when computer is turned off
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Secondary Memory

A
  • also used to store info, but it is much slower than main memory
  • can store even when there is no power to the computer (ex. Ssds and flash drives)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Input and output devices

A
  • simply our screen, keyboard, mouse, microphone, etc

- all the ways we interact with the computer

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

Network connection

A
  • the network is a very slow place to store and retrieve data that might not always be “up”
  • the network is a slower and at times unreliable form of secondary memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is your role as a programmer?

A

We, the programmers, are the people who answers the CPUs what’s next question

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

Program

A

The stored instructions

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

Programming

A

The act of writing these instructions down and getting the instructions to be correct

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

What are the “reserved words”?

A

There’s a whole list BUT

  • these words have a very special meaning to python
  • when python sees these in a program they have one and ONLY one meaning to Python
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the words you make up that hold meaning to python that aren’t the reserved words?

A

Variables

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

Variables

A
  • as you write programs you will make up your own words that have meaning to you called VARIABLES
  • you can use any name as a variable in python EXCEPT FOR THE RESERVED WORDS
  • we use this term Variable to refer to the labels we use to refer to this stored data
  • in algebra and symbolic logic- a variable is some unknown that we want to use in either statement, equation, etc.
  • (within reason) we can create as many variables as we want
  • sometimes we create them because the code needs them. Other times we create them to help us understand (ex. Circumference is d*Pi, but d can also be thought of as 2r)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Do CPUs understand English?

A

They only understand Machine Code. We use various translators to be able to understand this code and transmit it back to the computer

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

What is Python?

A

A high-level language intended to be straightforward to humans so we can use it to read and write to computers and so computers can read our inputs and process them

-python is a program itself and it is compiled into machine code

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

Interpreter

A
  • reads the source code of the program as written by the programmer, parses the source code, and interprets the instructions on the fly
  • python is an interpreter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Compiler

A
  • needs to be handed the entire program in a file, and then it runs a process to translate the high-level source code into machine language. Then the compiler puts the resulting machine language into a file for later execution
  • usually have a suffix of .exe or .dll which stands for “executable” and “dynamic link library”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do compiled languages work?

A

-you write code, you compile it, the machine executes it (ex. C or C++)

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

What is the python interpreter written in?

A

A high level language called C

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

Example of Python interpreted

A
  • you write code and hand it off to the interpreter(which is itself a program)
  • the interpreter compiles it to bytecode
  • the interpreter executes bytecode on a virtual machine
  • the virtual machine converts bytecode to a machine code
  • the physical machine executes it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

For an interactive python experience (you conversing with the computer), what do you need?

A

All you need is an interpreter

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

What do you need to create scripts or programs in Python?

A

A python interpreter, a text editor, and command land interface (CLI)

21
Q

Text editor

A
  • a text editor is a program that saves your files WITHOUT formatting
  • it saves the text as simple, plain text
  • ex. Imagine Word without all the formatting and printing options
  • for computers, bolding text is not saved as emboldened text but as bold text with a bold attribute tag
  • these tags are meant for visualization, not for computation. Therefore, when the computer reads the text and tries to execute it, it gives up, crashing, as if to say “How do you expect me to read THAT?”
  • these are specialized programs which are surprisingly featureless
  • many text editor developers know the primary intent is to code, so they build in features to help developers
22
Q

Command Line Interface (CLI)

A
  • I THINK it’s the interface we use to type and talk to python
  • we need a place to invoke the interpreter given our desired script or program
23
Q

What is an IDE?

A
  • stands for “Integrated Development Environment”
  • it’s a program dedicated to software development
  • IDEs integrate several tools specifically designed for software development
  • these tools usually include: an editor designed to handle code, Build, execution, and debugging tools, And some form of source control
  • ex. PyCharm, Spyder, Thonny
  • in these development tools everything is taken care of for you
  • this means things are “easier”, but when they break or don’t work, they’re incredibly complicated to fix
24
Q

Graphical user interface (GUI)

A

A visual way of interacting with a computer using items such as windows, icons, and menus used by most modern operating systems

25
Q

What is powershell/terminal?

A
  • operating systems tend to have a graphical user interface (GUI) as well as a command line interface (CLI)
  • when you are in PowerShell or Terminal you are talking to the operating system, analogous to clicking on a program’s icon

-there will be NO PowerShell or Terminal commands on an exam

26
Q

ls (LS)

A
  • Short for “list”

- will list the contents of your current directory

27
Q

cd (CD)

A
  • short for “change directory”

- ex. “cd code/cst150” will change your directory to “code/cst150”

28
Q

pwd (PWD)

A
  • short for “print working directory”

- will tell you what directory you’re in now

29
Q

Script

A
  • when we want to write a program, we use a text editor to write the Python instructions into a file, which is called a SCRIPT
  • the file is the script
  • Python scripts have names that end with .py

-a script is composed of many statements and comments

  • usually contains a sequence of statements
  • if there is more than one statement, the results appear one at a time as the statements execute. In order.
30
Q

Statements

A
  • a unit of code that the Python interpreter can execute
  • a section of code that represents a command or action

-statements contain one or many nested expressions

31
Q

Expressions

A
  • a combination of variables, operators, and values that represent a single result value
  • a value all by itself is considered an expression, and so is a variable
  • in a script an expression all by itself doesn’t do anything! (This is a common source of confusion for beginners)

-expressions are operators applies to (usually) one, two, or three variables or values
-can also be a variable or value by itself
Pg. 23

32
Q

Operator

A

-a special symbol that represents a simple computation like addition, multiplication, or string concatenation

Pg. 29

33
Q

Values

A
  • one of the basic units of data, like a number or a string, that a program manipulates
  • ex. 1, 2, “Hello, World!”
  • but these values belong to different TYPES

Pg. 19, 30, 99, 117

  • variables aren’t useful in isolation. What good is a variable if we never put an actual value in it?
  • that’s why we have values (some languages call them literals)
  • and how you type your value or literal determines the type in languages like Python
34
Q

All variables, values, and expressions evaluate to a…

A

Type

35
Q

What is a type?

A

-a category of values

  • it’s essentially a name and some expected behavior
  • concretely- it tells the compiler or interpreter how to use this data
  • these are the most common: string, integer, float, list, bool

Pg. 19, 30, 180

36
Q

What are the most common types in Python?

A

String, integer, float, list, bool

37
Q

String

A
  • a type that represents a sequence of characters
  • so-called because it contains a “string” of letters
  • you can identify strings because they are enclosed in either single or double quotation marks
  • ex. “Hello, World!” Or ‘Hello, World!’
  • you can display a string literal with the print() function
  • print (“Hello”)

Pg. 19, 30, 97, 126
Operation-pg. 24

38
Q

Integer

A
  • Int, or integer is a whole number, positive or negative, without decimals, of unlimited length
  • a type that represents whole numbers
  • ex. 9 or 22 or 2726472628
  • but NO decimals

Pg. 29

39
Q

Float

A
  • numbers with a decimal point belong to this type
  • these numbers are represented in a format called floating point

-the float() method is used to return a floating point number from a number or a string
-ex. Float(x) (let’s say x is 7) it would give us 7.0
-this method only accepts one parameter and that is also optional to use
Ex. Float(7) give us 7.0 you don’t have to use x

Pg. 19 Float Type
Pg. 44 Flor Function

40
Q

List

A
  • a list is a sequence of values
  • in a string, the values are characters; in a list, they can be ANY type
  • the values in a list are called elements or sometimes items
  • there are several ways to create a new list, the simplest is to enclose the items in square brackets (“[“ and “]”)
  • ex. [10, 20, 30, 40] (a list of four integers)
  • ex. [“crunchy frog”, “ram bladder”, “lark vomit”] (a list of three strings)
  • ex. [“spam”, 2.0, 5, [10, 20]] (list containing a string, a float, an integer, and another list!)

Pg. 91, 97, 105, 126

41
Q

Bool

A

-a Boolean expression is an expression that is either true or false

Pg. 31, 39, 71

42
Q

==

A

-an operator that compares two operands and produces True if they are equal and False otherwise
-ex. Operator used in Boolean expression
»> 5 == 5
True
»>5 == 6
False

43
Q

Comparison Operators

A
==
!=
><
>=
<=
Is 
Is not 
  • when writing conditions, we use comparison operators
  • these act on (compare) two values of the same type, such as two numbers or strings, but they always return a Boolean Value, either true or false, depending on if the condition is true or false
44
Q

X is Y

A
  • an operator

- x is the same as y

45
Q

X is not y

A
  • an operator

- x is not the same as y

46
Q

Things we need to be aware of when we name a variable

DA RULES OF NAMING A VARIABLE. GO.

A

Most names are going to be fine for a variable. Here are some exceptions:

  • cannot have a space
  • cannot be certain keywords reserved for the python language
  • cannot begin with a number (but can contain numbers)
  • cannot contain non-alpha-numeric characters (except underscore)
47
Q

What are non-alpha-numeric characters?

A

Non-alphanumeric characters comprise of all characters except alphabets and numbers

48
Q

Why aren’t variables good to use in isolation?

A

What good is a variable if we never put an actual value in it?

  • we have values (some languages call them literals)
  • and how you type your value or literal determines the type in languages like Python