business programing

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

1/79

flashcard set

Earn XP

Description and Tags

second exam

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

80 Terms

1
New cards

What is the purpose of a repetition structure?

To repeat a set of instructions multiple times until a certain condition is met.

2
New cards

How do you construct a repetition structure in a program flowchart?

Use a decision diamond to represent the condition, with arrows for “True” (loop back) and “False” (exit the loop).

3
New cards

How do you construct a WHILE loop?

Use a loop that continues to execute while a condition remains True.

4
New cards

What are the 3 steps to include in a WHILE loop?

  1. Initialize the loop control variable.

  2. Test the condition.

  3. Update the loop control variable.

5
New cards

What is an iteration variable?

A variable that keeps track of the number of iterations or controls how many times a loop runs.

6
New cards

How do you construct a definite WHILE loop?

Use a loop with a known number of iterations, typically controlled by a counter variable.

7
New cards

How do you construct an indefinite WHILE loop?

Use a loop that continues until a user or specific event stops it; condition depends on user input or a sentinel value.

8
New cards

What is meant by an infinite loop?

A loop that never ends because the condition never becomes False.

9
New cards

How do you construct a FOR loop?

Use the syntax for variable in iterable: followed by indented statements.

10
New cards

What is a target variable?

The variable that takes on each value in the iterable during each iteration.

11
New cards

What is meant by an iterable?

A sequence or collection of items that can be looped over, such as a list, string, or range.

12
New cards

Are lists iterables?

Yes.

13
New cards

Does the range() function produce an iterable?

Yes, it generates a sequence of numbers that can be looped through.

14
New cards

How do you construct a FOR loop that iterates through a list of values?

	

for item in [list]:

statement

15
New cards

What symbol represents a list?

Square brackets [ ].

16
New cards

Can a list be defined as a variable?

Yes, for example: numbers = [1, 2, 3].

17
New cards

How do you construct a FOR loop that iterates through a range of values?

	

for i in range(start, stop, step):

statement

18
New cards

What are the three arguments of the range() function?

start, stop, and step.

19
New cards

What happens when we use only 1, 2, or 3 arguments in range()?

1 argument → range(0, stop)
2 arguments → range(start, stop)
3 arguments → range(start, stop, step)

20
New cards

Which loops should you know how to code?

WHILE (definite and indefinite), FOR..in LIST, and FOR..in RANGE().

21
New cards

For any loop, how do you make it count up or count down?

Adjust the update statement or the step value in range() to increment or decrement.

22
New cards

What does the term iteration mean in loops?

One complete execution of the loop body.

23
New cards

How can you determine how many times a loop will iterate?

Evaluate how the loop control variable changes relative to its start, end, and step values or the condition.

24
New cards

What is an augmented assignment operator?

A shorthand way to update a variable’s value using an operation (e.g., x += 1 instead of x = x + 1).

25
New cards

What are the synonyms for augmented assignment operators?

Compound operators or shortcut operators.

26
New cards

What are the augmented assignment operators for mathematical operators?

Addition: +=
Subtraction: -=
Multiplication: *=
Division: /=
Integer Division: //=
Modulus: %=
Exponentiation: **=


27
New cards

What is the purpose of a counter variable?

To count the number of times a loop executes or an event occurs.

28
New cards

How do you initialize and update a counter variable?

Initialize before the loop (e.g., count = 0) and update inside the loop (e.g., count += 1).

29
New cards

What is a running total?

A variable that accumulates the sum of values as the loop iterates.

30
New cards

How do you initialize and update a running total?

Initialize before the loop (e.g., total = 0) and update inside (e.g., total += value).

31
New cards

What is input validation?

Ensuring the user enters valid data before proceeding.

32
New cards

How do you validate input using a while loop?

while value not valid:

ask for input again

33
New cards

When should you convert a user’s numeric input to int or float?

After validating the input to ensure it’s a valid number.

34
New cards

What does the break statement do?

Exits the loop immediately.

35
New cards

What does the continue statement do?

Skips the rest of the current iteration and moves to the next one.

36
New cards

What does the pass statement do?

Acts as a placeholder that does nothing; used to maintain syntax structure.

37
New cards

How do you construct a nested loop?

Place one loop inside another.

38
New cards

When should you write code in each of the 3 locations within a nested loop (A, B, C)?

A: Before the inner loop (setup actions)
B: Inside the inner loop (main repeated action)
C: After the inner loop (cleanup actions)

39
New cards

Can you nest different types of loops?

Yes, any loop type (WHILE, FOR in LIST, FOR in RANGE) can be nested inside another.

40
New cards

How do you write a nested loop to display tabular data?

Outer loop controls rows; inner loop controls columns.

41
New cards

What do we process in the outer loop?

The major grouping or row-level data.

42
New cards

What do we process in the inner loop?

The smaller repeated units or column-level data.

43
New cards

What is a function?

A piece of prewritten code that performs an operation.

44
New cards

What are examples of built-in Python functions?

print(), input(), int(), float(), type()

45
New cards

What is the purpose of writing your own functions?

To make code reusable, modular, organized, and easier to maintain.

46
New cards

What are the benefits of using functions?

  • Reduces complexity

  • Increases code reuse

  • Speeds up development

  • Easier to test and maintain

  • Improves quality

  • Decreases cost

47
New cards

What is top-down design?

Breaking a program into smaller subtasks, each coded as separate functions.

48
New cards

What is a modularized program?

A program whose tasks are divided into functions to organize code and promote reuse.

49
New cards

What are the two main types of functions?

Void functions and value-returning functions.

50
New cards

What is the difference between them?

  • Void functions perform an action but do not return a value.

  • Value-returning functions perform an action and return a value to the caller.

51
New cards

What are the two parameter types for functions?

  • With parameters (requires input values)

    • Without parameters (no inputs required)

52
New cards

What is a void function?

A function that does not return a value; typically just outputs information using print().

53
New cards

What is the syntax for defining a void function without parameters?

	

def function_name():

statements

54
New cards

What is a good naming convention for functions?

Use a verb phrase that describes what the function does.

55
New cards

Example of a void function without parameters:

	

def display_greeting():

print('\nWelcome User!')

56
New cards

Where must the function call to main() be placed in a Python program?

At the bottom, after all function definitions.

57
New cards

Why must main() be at the bottom?

Because a function must be defined before it can be called.

58
New cards

What is the difference between the “calling function” and the “called function”?

  • Calling function: The one that makes the function call (e.g., main()).

    • Called function: The one being executed (e.g., display_greeting()).

59
New cards

What is a parameter?

A variable listed in a function definition that receives input from outside the function.

60
New cards

What is an argument?

A value passed into a function when it is called.

61
New cards

How are parameters and arguments related?

The argument’s value is passed into the parameter during the function call.

62
New cards

What is the syntax for defining a function with a parameter?

	

def display_greeting(name):

print(f'Welcome, {name}!')

63
New cards

What is the syntax for calling a function with a parameter?

	

display_greeting('Bob')

64
New cards

What happens if you define a function that uses a parameter but call it without passing an argument?

You will get a TypeError, because the function is missing a required argument.

65
New cards

Can a function have multiple parameters?

Yes, for example:

def calc_total_pay(hours_worked, pay_rate):

total_pay = hours_worked * pay_rate

print(f'Total pay: ${total_pay:.2f}')

66
New cards

What are local variables?

Variables defined inside a function; only accessible within that function.

67
New cards

What is scope in Python?

The region of code where a variable is accessible.

68
New cards

Where is a local variable’s scope?

Only within the function it’s defined in.

69
New cards

Why must we pass values between functions using parameters?

Because functions do not automatically share local variables.

70
New cards

What is a dynamic greeting example using parameters?

	

def display_greeting(name):

print(f'Welcome, {name}!')

71
New cards

From the perspective of the programmer writing the function, what are they defining?

Parameters — the input values required by the function.

72
New cards

From the perspective of the programmer calling the function, what are they providing?

Arguments — the values passed to the function.

73
New cards

Can arguments be literals, variables, or expressions?

Yes — any of the three can be passed as arguments.

74
New cards

What is an optional parameter?

A parameter that has a default value and doesn’t require an argument to be passed.

75
New cards

What rule must optional parameters follow?

They must appear after all required parameters in the function header.

76
New cards

Example of a function with an optional parameter:

	

def greet(name='User'):

print(f'Welcome, {name}!')

77
New cards

What is one common error when using functions?

Forgetting to call main() at the bottom of the program.

78
New cards

Another common error?

Calling a function before it has been defined.

79
New cards

Why might a variable not be recognized in another function?

Because it was defined locally and not passed as a parameter.

80
New cards