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
Q

float

A

float
real numbers
have decimal point

26
Q

int

A

integer
integer

27
Q

complex

A

another type of data (ex: 3 + 4j) that I don’t need to know

28
Q

+

A

addition

29
Q

-

A

subtraction (or negotiation)

30
Q

*

A

multiplication

31
Q

/

A

division

32
Q

%

A

Integer division (aka leave off any remainder)

33
Q

//

A

integer

34
Q

**

A

exponent

35
Q

what happens if you divide by 0 in python?

A

error

36
Q

uses of %

A

obtain the last digit of a number
obtain the last 4 digits
see when a number is odd

37
Q

algorithms

A

a list of steps for solving a problem

38
Q

functions

A

a named group of functions

39
Q

procedural decomposition

A

dividing a problem into functions

40
Q

making a new function syntax python

A

def name():

          statement 

          statement 

          … 

          statement
41
Q

how to call a function in python

A

name()

42
Q

control flow in python

A

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
Q

place statements into a function if

A

The statements are related structurally, and/or
The statements are repeated

44
Q

You should not create functions for

A

an individual print statement
Only blank lines
Unrelated or weakly related statements

45
Q

precedence

A

Order in which operators are valued

Precedence in Python:
(**): Highest precedence
(*), (/), (//), (%): Same precedence are evaluated after exponentiation
(+),(-): Least precedence

46
Q

What data type is printed in this case: Integer (+ , - , //, *,) integer

A

integer

47
Q

What data type is printed in this case: Integer / integer

A

float

48
Q

What data type is printed in this case: Integer (+ , - , //, *,) float

A

float

49
Q

variable

A

a piece of computer’s memory that is given a name and type and can store a value

50
Q

declaring a variable

A

Declaring /initiate it - state its name and type and store a value into it

51
Q

Variable declaration and assignment

A

Variables must be declared before they can be used
The value can be an expression; the variable stores its result
Syntax: name = expression

52
Q

what = means

A

store the value at right in variable at left

53
Q

printing with multiple strings

A

add commas in between string and variable

54
Q

types of loops

A

for and while loops

55
Q

range (start, end)

A

start is inclusive
end is exclusive

56
Q

import random

A

imports the random module

57
Q

random.random()

A

returns a random float in the range (0.0, 1.0]

57
Q

random function we know

A

random.random()
random.randint(min, max)

58
Q

random.randint(min, max)

A

returns a random integer in the rand [min, max)

59
Q
A