Midterm 2

Here are some main points and a study guide from the provided sources about programming:

Main Points

Strings are immutable. This means that once a string is created, its contents cannot be changed in place.1234...

If you want to change a string, you need to reassign it, which means it will be moved to a different memory address.1346...

Parameter passing in Python is done by object reference. This means that when you pass a variable to a function, the function receives a reference to the original object, not a copy of it.128910

Lists are mutable. This means that you can change the contents of a list in place.56111213

Because lists are mutable, you can design functions that modify lists in place. You do not need to return a new list from the function.6111213

The .join() method can be used to join the elements of a sequence together into a string. The separator that is used to join the elements is specified as the first argument to the method.2

The open() function can be used to open a file for reading. The file name is passed as the first argument to the function.14

The for loop can be used to read a file one line at a time. The file object is used as the iterator in the for loop.14

The strip() method can be used to remove leading and trailing whitespace from a string.1415

Study Guide for Midterm 2

The content from week 7 of the course includes:

String Mutability

Definition of immutability

How to change a string using reassignment

How string mutability affects parameter passing

List Mutability

Definition of mutability

How to modify the contents of a list

How list mutability affects function design

String and List Methods

join() method

open() function

strip() method

Reading from a file

Using the for loop to read a file one line at a time

Using the strip() method to remove leading and trailing whitespace

The midterm will be on November 21st and will consist of 15 multiple-choice questions.16 To prepare, review:

All of the material covered in class, including the topics listed above.

All of the questions from the exit tickets and formative quizzes.

The in-class problem-solving activities from week 7.

Additional Tips for Studying

Use the Python visualizer to help you understand how code works.17

Work with other students to study and practice solving problems.18

Ask questions if you are unsure about anything.18

The provided excerpts did not contain information about tubers. If you have any questions about tubers, you may need to research them independently or contact the instructor.19

copy_all

thumb_up

thumb_down

keep_pinSave to note

Create study guide for second mid term, focus on weeks 4-7 and questions stated that will be on the mid term

Here is a comprehensive study guide for the second midterm, focusing on weeks 4-7, based on the provided sources:

Week 4

Functions

Void functions do not return a value.1

Fruitful functions return a value.1

Function definitions include a function name, parameters, and a body.23

Function calls execute the code inside a function.23

Formal parameters are inputs to a function and are local variables.2

Actual parameters are the values passed to a function when it is called, also called arguments.2

Loops

while loops repeat code as long as a condition is true.24

for loops iterate over a sequence of values.2

The range() function can be used to create a sequence of numbers.2

The in operator can be used to check if a value is in a sequence.2

Modules

Modules contain definitions and statements that can be used in other programs.5

The import statement is used to import a module.5

The turtle module provides functions for creating graphics.6

Basic drawing commands include forward(), left(), and right().6

Pen control commands can be used to change the color and width of the pen.6

Recursion

A recursive function is a function that calls itself.7

Recursive functions need:

A base case, which is a condition that stops the recursion.7

A recursive case, where the function calls itself with a smaller or larger input to get to the base case.7

The call stack manages function calls in a last-in, first-out (LIFO) manner.7

Each time a function is called, a new frame is added to the call stack.7

When a function returns, its frame is removed from the call stack.7

Midterm 1 Review

Review the questions from formative quizzes 1 and 2.8

Practice tracing code execution.8

Week 5

Call Stack

Manages any function calls in a last-in, first-out (LIFO) manner.9

A new "stack frame" is created when a function is called and pushed onto the call stack.9

The stack frame stores the information needed to manage the specific function call.9

When a function completes, its stack frame is popped off the stack.10

Control then returns to the calling function using the return address in the stack frame.10

Recursion (continued)

Practice tracing recursive functions using the call stack.7

Project: Drawing squares recursively11

Focus on understanding the base case and the recursive case.11

Midterm 1 Feedback12

Review the answers and explanations for the midterm questions.9

Week 6

Refactoring

The process of improving the design of existing code without changing its external behavior.1314

Benefits include:

Increased readability.13

Reduced complexity.13

Improved maintainability.13

Consider function design and parameter choices during refactoring.1315

Apply refactoring principles to both algorithms and user interfaces.16

Mutability

Immutable objects, like strings, cannot be changed in place.17

Mutable objects, like lists, can be changed in place.18

Understand how mutability affects memory addresses and variable assignment.1718

The id() function can be used to view the memory address of an object.17

String and List Operations18

Slicing can be used to extract a portion of a string or list.17

Concatenation combines two sequences.19

Project 6 Introduction: Hangman game20

Start thinking about how to decompose the problem into smaller functions.20

Week 7

List Methods21

append(): adds an element to the end of a list.21

index(): returns the index of the first occurrence of a value.21

insert(): inserts an element at a specified index.21

remove(): removes the first occurrence of a value.21

sort(): sorts the elements of a list.21

Important: These methods modify the original list (lists are mutable).21

String Methods21

capitalize(): capitalizes the first letter of a string.21

isalpha(): returns True if all characters are letters.21

isdigit(): returns True if all characters are digits.21

isupper(): returns True if all characters are uppercase.21

split(): splits a string into a list of words.21

upper(): converts all characters to uppercase.21

find(): returns the index of the first occurrence of a substring.21

Reading from a file (continued)

Use open() to open a file for reading.19

Use a for loop to read the file line by line.19

Use strip() to remove whitespace from the beginning and end of each line.19

Midterm 2 Preparation22

The midterm will be on November 21st and will cover the first seven weeks of the course.2223

It will consist of 15 multiple-choice questions and one writing code question.2223

Review all materials from weeks 4-7, including exit tickets, formative quizzes, and in-class activities.22

Practice tracing code and solving problems similar to those covered in class.22

Practice Questions for Midterm 2 (stated in sources)

From Week 3 (will be on Midterm 2):2324

Recall the concept of short circuit evaluation.25

Identify and understand the use of different loop structures like for and while loops.26

Understand the concept of keywords in Python and how they are interpreted.26

Trace the execution of code with loops and conditional statements.24

From Week 4:27

Trace recursive functions using the call stack.27

From Week 7:24

Identify the three function designs in Python.18

Note: The specific content of Midterm 2 will be based on the topics covered in weeks 4-7. It is recommended to pay attention to the practice problems and examples discussed in class, as similar concepts and questions may appear on the exam.

Additional advice from the sources:

Form study groups: Collaborating with classmates can be helpful in understanding the material and practicing problem-solving.8

Utilize Python visualizer/tutor: This tool can help you visualize code execution step-by-step and understand the logic behind different constructs.2829

Actively participate in class: Ask questions when unsure about a concept and engage in discussions to solidify your understanding.34612...

This information should help you prepare for the second midterm. Please note that this study guide is based solely on the provided sources and does not cover all possible topics for the exam. Be sure to consult your class notes, textbook, and any other relevant materials for a comprehensive understanding of the course content.