Python Exam 1 Flashcards

1
Q

How do humans solve problems?

A

cognitive abilities and intuition

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

How do computers solve problems?

A

Rely on computational power and algorithmic precision

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

different types of programming language

A

machine language, assembly language, high-level language

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

machine language

A

the limited set of instructions that a CPU can understand directly
Each instruction sequence of 1s and 0s
Binary digits or bits for shorts
the CPU executes the instructions

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

Assembly language

A

Each instruction is defined by a short abbreviation
The CPU can not understand assembly language directly –> translated into machine language using a processor

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

High-Level Language

A

For more readability and portability high-level language:
uses English like language
machine-independent
portable
examples: python, Pascal, C, C++, java, Fortron
Must be translated: 2 primary ways of translation: compiler and interpreter

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

2 primary ways of translation

A

compiler and interpreter

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

compiler

A

is a program that reads SOUCE CODE and produces a STAND-ALONE EXECUTABLE that can then be run

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

interpreter

A

program that directly executes the instructions in the source code w/o requiring them to be compiled into an executable first

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

About Python

A

high level general purpose
interpreted language
code executed line by line
run code without compiler

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

Why python?

A

relatively simple
pre-written software
widely used
general purpose

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

Python file extension

A

.py

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

What is a terminal also called?

A

terminal, console, output

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

string

A

a sequence of text characters
starts and ends with a “quote” character or a ‘quote’ character
quotes do not appear in output

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

String rules

A

strings surrounded by “” or ‘’ may not span multiple lines
strings surrounded by “” may not contain a “ character (unless using esc. seq)
strings surrounded by ‘’ may not contain a ‘ character (unless using esc. seq)

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

Escape sequence

A

used to represent certain special characters in a string
\t
\n
"
'
\

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

\t

A

tab key

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

\n

A

new line character

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

\”

A

quotation mark character

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

'

A

quotation mark/apostrophe character

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

\

A

backslash character

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

string addition

A

use plus operator +

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

comments

A

are notes written in source code by the programmer to describe/clarify the code
not displayed
# or “”” “””

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

Data types

A

a category or set of data values
constrains the operations that can be performed on data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
float
float real numbers have decimal point
26
int
integer integer
27
complex
another type of data (ex: 3 + 4j) that I don't need to know
28
+
addition
29
-
subtraction (or negotiation)
30
*
multiplication
31
/
division
32
%
Integer division (aka leave off any remainder)
33
//
integer
34
**
exponent
35
what happens if you divide by 0 in python?
error
36
uses of %
obtain the last digit of a number obtain the last 4 digits see when a number is odd
37
algorithms
a list of steps for solving a problem
38
functions
a named group of functions
39
procedural decomposition
dividing a problem into functions
40
making a new function syntax python
def name(): statement statement … statement
41
how to call a function in python
name()
42
control flow in python
when a function is called, the program's execution jumps int that function, executes its statements, then jumps ack to the point where the function was called
43
place statements into a function if
The statements are related structurally, and/or The statements are repeated
44
You should not create functions for
an individual print statement Only blank lines Unrelated or weakly related statements
45
precedence
Order in which operators are valued Precedence in Python: (**): Highest precedence (*), (/), (//), (%): Same precedence are evaluated after exponentiation (+),(-): Least precedence
46
What data type is printed in this case: Integer (+ , - , //, *,) integer
integer
47
What data type is printed in this case: Integer / integer
float
48
What data type is printed in this case: Integer (+ , - , //, *,) float
float
49
variable
a piece of computer's memory that is given a name and type and can store a value
50
declaring a variable
Declaring /initiate it - state its name and type and store a value into it
51
Variable declaration and assignment
Variables must be declared before they can be used The value can be an expression; the variable stores its result Syntax: name = expression
52
what = means
store the value at right in variable at left
53
printing with multiple strings
add commas in between string and variable
54
types of loops
for and while loops
55
range (start, end)
start is inclusive end is exclusive
56
import random
imports the random module
57
random.random()
returns a random float in the range (0.0, 1.0]
57
random function we know
random.random() random.randint(min, max)
58
random.randint(min, max)
returns a random integer in the rand [min, max)
59