Python Object-Oriented Programming and Simulation Final Exam Guide

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

1/145

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.

146 Terms

1
New cards

Data types

Categories of data that determine the type of value a variable can hold, including int, float, string, and bool.

2
New cards

Basic math operations

Fundamental arithmetic operations including addition (+), subtraction (-), multiplication (*), division (/), floor division (//), and modulus (%) in programming.

3
New cards

User input

Data that is provided by the user to the program during execution.

4
New cards

Conditional statements

Statements that execute different actions based on whether a specified condition evaluates to true or false, including if, elif, and else.

5
New cards

Try-Except

A block of code used to handle exceptions or errors that may occur during the execution of a program.

6
New cards

F-string

A string formatting method in Python that allows embedding expressions inside string literals, prefixed with 'f'.

7
New cards

List

A collection data type in Python that is ordered and mutable.

8
New cards

List methods

Functions that can be applied to lists, such as append(), remove(), and sort().

9
New cards

While / For loop

Control flow statements that allow code to be executed repeatedly based on a condition (while) or iterating over a sequence (for).

10
New cards

Break/ continue/ pass

Control statements used within loops; break exits the loop, continue skips to the next iteration, and pass does nothing.

11
New cards

Nested loop

A loop inside another loop, allowing for more complex iterations.

12
New cards

Functions

Reusable blocks of code that perform a specific task, can be built-in or user-defined.

13
New cards

Parameters & argument

Parameters are variables in a function definition, while arguments are the actual values passed to the function.

14
New cards

Scope (LEGB rule)

The rule that defines the order of variable scope resolution: Local, Enclosing, Global, Built-in.

15
New cards

Dictionary

A mutable, unordered collection of key-value pairs in Python.

16
New cards

Tuples

An immutable sequence type in Python.

17
New cards

Sets

An unordered collection of unique elements in Python.

18
New cards

Frozensets

An immutable version of a set in Python.

19
New cards

Class & Object

Class is a blueprint for creating objects, which are instances of classes.

20
New cards

Attributes & Methods

Attributes are variables that belong to a class, while methods are functions defined within a class.

21
New cards

Constructors (Initialization Methods)

Special methods in a class that are called when an object is instantiated.

22
New cards

Getters and Setters

Methods used to access and modify the attributes of a class.

23
New cards

Inheritance

A mechanism in object-oriented programming where a new class can inherit attributes and methods from an existing class.

24
New cards

Garbage collector

A system that automatically manages memory by reclaiming memory occupied by objects that are no longer in use.

25
New cards

Syntax error

An error that occurs when the code does not conform to the rules of the programming language.

26
New cards

Logical error

An error that produces incorrect results but does not crash the program.

27
New cards

Data type

A classification that specifies which type of value a variable can hold.

28
New cards

Identifier

A name used to identify a variable, function, class, or other object.

29
New cards

String

A data type that can contain a combination of numbers, letters, and symbols.

30
New cards

Variable

A location in memory used to store data that can later be altered.

31
New cards

Assignment operator

The symbol used in Python to assign values to a variable, which is '='.

32
New cards

String concatenation

A method that combines two or more string values.

33
New cards

input() function

A built-in function that processes and stores user input data as a string.

34
New cards

Conversion of float to integer

When converting a float to an integer, fractional values are truncated, not rounded.

35
New cards

Try Except Block

A block of code used for handling exceptions in Python.

<p>A block of code used for handling exceptions in Python.</p>
36
New cards

if statements

Statements used to evaluate single or multiple-alternative decisions.

<p>Statements used to evaluate single or multiple-alternative decisions.</p>
37
New cards

What operator for conditional statements

Comparison (>,<, =), Membership (in, not in), Logical (and), and Boolean (True/False) are used in conditional statements.

38
New cards

Logical operator

Operators used to evaluate conditions, such as AND, OR, and NOT.

39
New cards

Membership Operators

Used for checking if a given object does or does not contain a specific value.

40
New cards

elif Statements

Useful for checking multiple condition statements, one after the other, as part of the same decision structure.

41
New cards

Data Collection

Useful for storing multiple elements within a single container.

42
New cards

Nested List

A list embedded in a list.

43
New cards

While Loops

Indefinite loop structures.

44
New cards

For Loops

Definite loop structures.

45
New cards

Continue Statement

Jumps to the 'top' of the loop and starts the next iteration.

46
New cards

Break Statement

Exits the currently executing loop.

47
New cards

Pass Statement

Useful for testing and working through the logic of code, without having written code statements in the loop.

48
New cards

List Loop

A loop that is used to iterate over the items contained within a list.

49
New cards

Function Call Statement

A statement that calls a function without a syntax error.

<p>A statement that calls a function without a syntax error.</p>
50
New cards

Intermediate Variable

A variable used to store temporary values during calculations.

51
New cards

Python Variable Name

An identifier used to name a variable in Python.

52
New cards

Boolean Operators

Operators used to evaluate conditional statements.

53
New cards

Logical Operators

Operators that determine the logic of expressions.

54
New cards

Immutable List

A list that cannot be modified after it is created.

55
New cards

Garbage Collection

The process of automatically freeing memory by removing objects that are no longer in use.

56
New cards

Data Type Checking

The process of verifying the type of data stored in a variable.

57
New cards

User Input Handling

The process of managing data entered by users.

58
New cards

number

e.g., 1

59
New cards

quotes

e.g., " "

60
New cards

Which of the following is the most appropriate data type to store a circle's radius?

61
New cards

Which of the following is the most appropriate data type to store a zipcode?

62
New cards
<p>What will be the output of the code below, assuming the user enters 10 and 8?</p>

What will be the output of the code below, assuming the user enters 10 and 8?

10, 8, 18, 80, 108, None of the above

63
New cards

Question 45

What will be the output of the code below? 0, 1, 2, 3, None of the above

64
New cards

Question 46

What will be the output of the code below? hun, m hu, h, hun, hu, None of the above

65
New cards

Question 47

Which of the following expressions evaluates to True? 10 < 5 * 2, 3 = 3, 7!=7, 5>=2, None of the above

66
New cards

Question 48

What will the following code print? Success, Error, None of the above

67
New cards

Question 49

What will the following code print in the LAST line of the output? Valid, Invalid, None of the above

68
New cards

Question 50

What will the following code print? Condition Met, Condition Not Met, Error, Nothing will be printed

69
New cards

Question 51

What will the following code print? High Ration, Medium, Low, Error (zero division), Nothing will be printed

<p>What will the following code print? High Ration, Medium, Low, Error (zero division), Nothing will be printed</p>
70
New cards

Question 52

What will the following code print? Checking... Cannot divide by zero, Cannot divide by zero, Checking... Division successful, Cannot divide by zero, None of the above

71
New cards

Question 53

What will the following code print? numbers = [0, 5, 10, 0, 15] index = 0 total = 0 count = 0 while index < len(numbers): if numbers[index] != 0: total += numbers[index] count += 1 index += 1 mean = total / count while index < len(numbers): if numbers[index] == 0: numbers[index] = mean index += 1 print("Updated list:", numbers) Updated list: [0, 5, 10, 0, 15], Updated list: [10.0, 5, 10, 10.0, 15], Updated list: [10.0, 5, 10.0, 10.0, 15], None of the above

<p>What will the following code print? numbers = [0, 5, 10, 0, 15] index = 0 total = 0 count = 0 while index &lt; len(numbers): if numbers[index] != 0: total += numbers[index] count += 1 index += 1 mean = total / count while index &lt; len(numbers): if numbers[index] == 0: numbers[index] = mean index += 1 print("Updated list:", numbers) Updated list: [0, 5, 10, 0, 15], Updated list: [10.0, 5, 10, 10.0, 15], Updated list: [10.0, 5, 10.0, 10.0, 15], None of the above</p>
72
New cards

Question 54

What will the following code print? Suppose the user enters "N" and then "Y" response1 = input("Are you off campus? (y/n): ") if response1 == "y": print("Go to Putter's") else: response2 = input("Are you near the Biz School Building? (y/n)") if response2 == "y": print("Go to Einstein!") else: print("Go to Reynolda!") Go to Putter's, Go to Einstein!, Go to Reynolda!, None of the above

<p>What will the following code print? Suppose the user enters "N" and then "Y" response1 = input("Are you off campus? (y/n): ") if response1 == "y": print("Go to Putter's") else: response2 = input("Are you near the Biz School Building? (y/n)") if response2 == "y": print("Go to Einstein!") else: print("Go to Reynolda!") Go to Putter's, Go to Einstein!, Go to Reynolda!, None of the above</p>
73
New cards

Question 55

What will the following code print? Suppose the user enters "N" and then "Y" messy_text = "_ Welcome to python programming! _" clean_text = messy_text.strip() print(clean_text) _ Welcome to python programming! _, _Welcome to python programming!_, Welcome to python programming! , None of the above

74
New cards

Question 56

What method type provides a secure way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by code outside the method? accessor, mutator, setter, class

75
New cards

Question 57

A value-returning function is described as: a single statement that performs a specific task, called when you want the function to stop, a function that will return a value back to the part of the program that called it, a function that receives a value when called

76
New cards

Question 58

Methods written to change attribute values are known as: getter, setter, instances, constructors

77
New cards

Question 59

What will be the value of the variable list2 after the following code executes? [1, 2, 3], [4, 5, 6], [1, 2, 3, 4, 5, 6], Nothing; this code is invalid

78
New cards

Question 60

When there are several classes that have many common data attributes, it is better to write a(n) __________ to hold all the general data. superclass, subclass, object, method, class attributes

79
New cards

Question 61

Data and code combined into a single object is known as: modularity, instantiation, encapsulation, objectification

80
New cards

Question 62

What does a subclass inherit from a superclass? instances and attributes, objects and methods, methods and instances, attributes and methods

81
New cards

Question 63

Which of the following is the correct syntax for defining a class, dog, which inherits from the animal class?

82
New cards

Worker class object creation

To create an object, worker_joey, of the Worker class, use: worker_joey = Worker()

83
New cards

Dictionary display order

The order of the display of entries in a dictionary are not in a specific order.

84
New cards

Function call values

Arguments are the values that are sent to a function when it is called.

85
New cards

Tuple vs List

Once a tuple is created, it cannot be changed.

86
New cards

Dictionary key

In a dictionary, you use a key to locate a specific value.

87
New cards

Python function return

You can return data collections.

88
New cards

Sets characteristics

The elements are in pairs does not apply to sets.

89
New cards

Tuple advantage

Tuples can be used for storing static unchanging values.

90
New cards

Range function output

The output of range(0, 20, 5) is 0, 5, 10, 15.

91
New cards

Code block average calculation

It accepts 3 test scores for each of 3 students and outputs the average for each student.

92
New cards

Avoiding global variables

By convention programmers should avoid using global variables in programs if possible.

93
New cards

Code execution output

The resulting output after the code execution is 81.

94
New cards

Code execution output with syntax error

The statement contains a syntax error.

95
New cards

Code execution output with names

The resulting output after the code execution is Julian, Smith.

96
New cards

Concept of abstraction

Hiding unnecessary details and complexity from the user best describes the concept of abstraction.

97
New cards

Self in Python methods

Self is typically used to refer to the instance in which the method is being called.

98
New cards

Class extension access

In order to extend a class, a new class should have access to all the data and inner workings of the parent class.

99
New cards

User-defined functions

A variable created within a function can only be accessed inside that function.

100
New cards

Code output question

What will be the output of the following code?