Lecture 2 - Input, Processing, and Output Flashcards

1
Q

What is the three-step process a typical computer program performs?

A

obtain input: any data the program receives while it is running

perform some processing on the input: this could be simple (e.g., arithmetic calculation) or complex (e.g., full nature-language processing algorithm)

produce output: based on the input and processing

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

What is a function?

A

some pre-written code that performs an operation
A function is a black box (probably containing programming language statements, but not always) that accepts arguments from a program statement and which calculates a result value that is returned to the program statement ( where that value might be ignored!) and which also might have some possible side-effect on the computer itself.

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

What is print() ?

A

a built-in Python function that displays textual output onto the screen / console

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

What is argument?

A

the data given to a function

e.g., print(“University of Victoria”) would display the words “University of Victoria”

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

What is sequential order?

A

when statements are executed in the order they appear - from top to bottom

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

What is a string?

A

a sequence of characters

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

What is a string literal?

A

a string whose complete value appears in the code for the program

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

What are string literals enclosed by?

A

pairs of single quotes (‘) or pairs of double quotes (“)

There is also a special triple quote (“””) available for string literals (which permits them to span several lines if this is needed)

String literals must be ended using the same quotation mark with which they were begun.

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

What is a variable?

A

a name that represents a value stored in memory - we use such names to access and manipulate data in main memory

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

What is an assignment statement used for?

A

to associate a variable with a data value

the = symbol is used to indicate assignment

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

What are some variable naming rules?

A

Variable names cannot contain spaces
First character must be a letter or an underscore but after the first letter, you may use letters, digits, or underscores
Variable names are case sensitive
Variable names should reflect their purpose
Variable names cannot be a Python keyword

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

What is the main way that Python denotes comments?

A

When the # symbol appears on a Python line, Python ignores everything following that symbol.

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

What is variable reassignment?

A

Variables may reference different values at different times while a program is running
Values that were once referenced by a variable name but which at some point during the same interpreter session are no longer referenced by any variable name will have their memory-space allocation reclaimed by the interpreter (i.e., technically called garbage collection).

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

What are data types?

A

A data type is the way a high-level programming language categorizes a set of values that may be stored in memory and which also indicates the legal operations permitted on such a set.
Some operations may even behave differently depending upon the data type of the values given to the operation.

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

What are three examples of data types?

A
integer (or int)
floating point (or float) for real numbers
string (or str)
A variable always has some type for the value assigned to it!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

String literal

A

sequence of characters

17
Q

Integer literal

A

number has no decimal point

18
Q

Floating-point literal

A

number has a decimal point

19
Q

How doe the function input() work?

A

Python function input() reads a line from the user’s keyboard. When called, the program prints the given prompt message and then pauses while waiting for the user to type something. After user types in some text and presses return or enter, then the program resumes. The input() function always returns the data as a string.
If we want a different data type from the user’s input (e.g., an int or a float), we will add additional statements following input().

20
Q

What are expressions?

A

These are programming-language building blocks needed to specify calculations on numeric values.
Requires a math operator to indicate the needed operation (i.e., for the needed calculation)
Requires operands (i.e., values needed by the operator)
A expression may consist of more than operation

21
Q

What are the operators for simple calculations?

A
Addition (+)
subtraction (-)
Multiplication (*)
Floating-point division (/)
Integer division (//)
Modulus, also known as the "remainder" operation (%)
Exponentiation (**)
22
Q

The value returned from input() is always a…?

A

string

23
Q

What do mixed-type arithmetic expressions result in?

A

Two ints result in an int
Two floats result in a float
One int with one float results in a float

24
Q

What can we do with the print() function?

A

For each call to print() - Output always appears on a separate line.
For multiple arguments - it prints a space between arguments as they are output.
For numeric output - it prints out repeating digits in some floats.
We can suppress the newline performed with each call to print().
We can also change the character inserted between multiple arguments (i.e., change from the default of inserting a space).
This is accomplished via the use of keyword arguments to print().

25
Q

What is format() ?

A

Another built-in Python 3 function
Accepts two arguments (an integer or float either as a literal or a variable; followed by a format specifier)
Returns one value (a new string)
The idea:
We use format() to create a string based on the number and then provide that string as an argument to print().

26
Q

What is the typical program development cycle?

A
Design the program
Write a draft of the code
Correct for syntax errors
Test the program
Correct logic effort
Go back to an earlier step if needed
27
Q

What does design mean in this context?

A

Breaking down each task described in the requirments into a series of simpler steps
Create an algorithm that lists these solutions steps in a logical way

28
Q

What is an algorithm?

A

A set of well-defined logical steps that must be taken to perform a task that is precise enough such that each of the steps can be written using building blocks from our programming language.

29
Q

What is pseudocode?

A

Pseudocode is meant to be used informally (i.e., no strict syntax rules)
Pseudocode is not meant to be executed directly.
Pseudocode instead helps us explore program-design ideas without committing ourselves to actual programming-language code
Ideally there is a short distance from pseudocode to actual code, but recognising this only comes after getting more programming experience.

30
Q

What is a flowchart?

A

A flowchart is a diagram depicting (in visual form) the steps taken by a program

31
Q

What are the symbols used in flowcharts? What do they represent?

A

ovals / rounded rectangles: terminals (i.e., starting & stopping points)

parallelograms: input/output
rectangles: processing
arrows: represent sequence of operations (i.e., control flow) in the program