Midterm Study Guide Fall 2024.docx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

CS121 Midterm Study Guide Midterm exam is composed of writing test and programming test. Writing test is close-book while programming test is open-book. The whole test should be finished within 2 hours with one sitting. You can bring in a cheating sheet using both sides. **Chapter 1 Introduction**...

CS121 Midterm Study Guide Midterm exam is composed of writing test and programming test. Writing test is close-book while programming test is open-book. The whole test should be finished within 2 hours with one sitting. You can bring in a cheating sheet using both sides. **Chapter 1 Introduction** Review Zybook 1.2, 1.3, 1.4, and 1.6. Key concepts are: - Python interpreter - Comments, \# - Input/output functions - Type of program errors: syntax errors, runtime errors, and logic errors - Understand the concepts of processors, memory, compilers/interpreters, machine instructions, and high-level languages. Compilers/interpreters are programs that translate high-level language programs to executable programs. **Chapter 2 Variables and Expressions** Review lecture PPTs of chapter 2, and Zybook 2.1 - 2.10. Key concepts: - Variables and assignment operator = - Rules to name Python identifiers: letters, digits, and \_ - What are objects, name binding, and properties of objects - Floating-point numbers, what is an overflow, how to control decimal places - Unicode for character representation, ord() and chr() functions - Escape sequences - Arithmetic expressions, and precedence rules of arithmetic operators - Division, floor division, modulo - Shorthand operators: +=, /=, \*=, -= - Math module, import statement **Chapter 3 Types** Review PPTs and Zybook 3.1---3.9. Key concepts: - String basics: index for string characters starts from 0, strings are immutable, string concatenation (+). str = 'Monday', str\[0\] returns 'M' - List basics: index for list elements starts from 0; lists are mutable; syntax for list definition: student\_names = \['Jim', 'Peter', 'Katie'\] student\_names\[1\] returns 'Peter' Functions that manipulate a list: list.append(value), list.pop(i), list.remove(v) Pay attention to the different argument meanings of the above functions. - Tuple basics: index for tuple elements starts from 0; tuples are immutable; syntax for tuple definition uses (), not \[\]: student\_names = ('Jim', 'Peter', 'Katie') student\_names\[1\] returns 'Peter' Namedtuple module can be imported to define a new simple data type that consists of multiple attributes. Check the Car example. - Set basics: No index for set elements, since a set is unordered. sets are mutable; set elements are unique; syntax for set definition: nums = set ( \[1, 2, 3\] ), or nums = {1, 2, 3} create the same set. Set manipulation functions: add, remove, pop, clear, update, len (len function is available for all sequence types) Between-set operations: intersection, union, difference, symmetric\_difference - Dictionary basics: describing the associative relationships between **key**s and **value**s. No index for dictionary elements; mutable; syntax for dictionary: prices = {\'apples\':1.99,\'oranges\':0.99, \'banana\':0.49} print(prices\[\'apples\'\]) How to add a new entry, modify existing entries, and remove entries. - Type conversions: implicit and explicit (int(), float(), str()) - Binary number and decimal number conversion - String formatting: print(f'...{var: X}...') **Chapter 4 Branching** Review the lecture PPTs and Zybook 4.1---4.12. PPT Chap04\_1 and Chapt04\_2: - If statement, if-else statement, multi-branch if-else statement, nested if-else statement - Detecting ranges: continuous range and range with gaps - Relational operators and logical operators - Distinct if statements vs. grouped if statements Student grade example and exact change example - How to compare different data types: int, float, strings (what is the order between strings?) - How to compare two lists/tuples? Which is bigger? - How to compare two dicts? Only equal or not, cannot decide order. PPT Chap04\_3: - Membership and identity operators (in/not in, is/is not) Example - Order of evaluation (arithmetic\>relational\>logical\>assignment) - Code blocks and indentation - Conditional expressions: exp1 if condition else exp2 **Chapter 5 Loops** Review the lecture PPTs and Zybook 5.1---5.8. - While loops and for loops - When to use which? Do you know number of iterations before entering the loop? - Infinite loops - Sentinel values: the user can enter an arbitrary number of input until a sentinel value is entered. - random module: random.randint(0,2) returns a random number in the range \[0, 2\] - range() function: return a list of integers not including the end value. - Nested loops, challenge activity 5.8.3

Use Quizgecko on...
Browser
Browser