CSC 203 chapter 3: Control Statements and Program Development

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/46

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

47 Terms

1
New cards

algorithm

a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute.

2
New cards

program control

Specifying the order in which statements (actions) execute in a program

3
New cards

pseudocode

An informal language that helps you develop algorithms without worrying about strict Python syntax; similar to everyday English and easily converted to a program.

4
New cards

pseudocode normally describes

Only statements representing actions that occur (e.g., input, output, or calculations).

5
New cards

sequential execution

statements in a program execute in the order in which they’re written.

6
New cards

transfer of control

the next statement to execute is other than the next one in sequence; achieved with control statements

7
New cards

The three forms of control written in all programs

  1. Sequential execution

  2. Selection statement

  3. Iteration statement

8
New cards

Flowchart

A graphical representation of an algorithm or a part of one. Uses rectangles, diamonds, rounded rectangles, and arrows (flowlines) to show how forms of control operate.

9
New cards

Rectangle

indicates any action

10
New cards

Flowlines

arrows that show the order in which the actions execute

11
New cards

In a flowchart for a complete algorithm,

the first symbol is a rounded rectangle containing the word “Begin.” The last symbol is a rounded rectangle containing the word “End.”

12
New cards

In a flowchart for only a part of an algorithm,

use small circles called connector symbols.

13
New cards

Three selection statements that execute code based on a condition—an expression that evaluates to either True or False

  • if performs an action if a condition is True or skips the action if the condition is False.

  • if... else statement performs an action if a condition is True or performs a different action if the condition is False .

  • if... elif... else statement performs one of many different actions, depending on the truth or falsity of several conditions.

14
New cards

Two iteration statements

while and for

15
New cards

suite

group of statements controlled by a clause. Must be indented after a statement

16
New cards

Diamond

symbol for decision. Contains a condition that can be either True or False. Two flowlines emerging from it:

  • One indicates the direction to follow when the condition in the symbol is True

  • The other indicates the direction to follow when the condition is False

17
New cards

if… else statement flowchart

knowt flashcard image
18
New cards

if... elif... else statement

Can test for many cases. Only the action for the first True condition executes.

19
New cards

if... elif... else statement flowchart

knowt flashcard image
20
New cards

is else required or optional?

optional. Handles values that do not satisfy any of the conditions. Without an else, if no conditions are True, the program does not execute any of the statement’s suites.

21
New cards

while statement

Repeats one or more actions while a condition remains True. 

To prevent an infinite loop, something in the while suite must change product's value, so the condition eventually becomes False

22
New cards

while statement flowchart

knowt flashcard image
23
New cards

for statement

Repeat an action or several actions for each item in a sequence of items (e.g., string, list, or range)

24
New cards

string

a sequence of individual characters

25
New cards

Function print()’s end Keyword Argument

Changes what is printed after each item (default is a newline). print(character, end=' ')

26
New cards

Function print()’s sep Keyword Argument

Specifies what separates printed items (default is a space). print(1,2,3, sep=', ').

27
New cards

iterable

An object from which the for statement can take one item at a time

28
New cards

list

a comma-separated collection of items enclosed in square brackets [ ]. Mutable

29
New cards

Mutable

contents can be changed, added to, or removed after creation

30
New cards

range() function

Creates an iterable object that represents a sequence of consecutive integer values starting from 0 and continuing up to, but not including, the argument (end) value.

31
New cards

Augmented assignments

shorthand assignment where a variable updates itself

  • *=

  • +=

  • -=

  • /=

  • //=

  • **=

  • %=

32
New cards

sentinel values

denotes the end of a data set, but it is not part of the data

33
New cards

sentinel-controlled iteration

number of iterations is not known in advance. The loop continues to execute until a specific "sentinel value" is encountered, which acts as a signal to terminate the loop

34
New cards

f-string (formatted string)

allows inserting values into a string. The letter f before the string's opening quote indicates it's an f-string. You specify where to insert values by using placeholders delimited by curly braces { }. Replacement-text expressions (what’s inside { }) may contain values, variables, or other expressions.

35
New cards

Modifier

In an f-string, you can optionally follow a replacement-text expression with a colon (:) and a format specifier that describes how to format the replacement text.

36
New cards

Formatting type :.2f

The format specifier . formats the input as a floating-point number (f) with two digits to the right of the decimal point (.2). Rounds to the hundredths position

37
New cards

range(start, end+1, step)

  • position to start. Default is 0

  • position to end before

  • increment it if step is positive. decrement (go backwards) if step is negative

38
New cards

Formatting type :>2

right aligned (>) in a field of width 2

39
New cards

Formatting type :<

left aligned

40
New cards

break statement

immediately terminates the loop

41
New cards

continue statement

skips the rest of the current iteration of the loop and proceeds to the next iteration

  • In a while, the condition is then tested to determine whether the loop should continue executing

  • In a for, the loop processes the next item in the sequence (if any)

42
New cards

Boolean Operator and

Ensure that two conditions are both True

43
New cards

Boolean Operator or

Ensure that one or both of two conditions are True

44
New cards

Boolean Operator not

“Reverse” the meaning of a condition

45
New cards

mean

the average value in a set of values.

import statistics

statistics.mean(list)

46
New cards

median

the middle value when all the values are arranged in sorted order.

import statistics

statistics.median(list)

47
New cards

mode

the most frequently occurring value.

import statistics

statistics.mode(list)