Problem solving final exam guide, Summaries of Physics

Summery of problem solving exam guide

Typology: Summaries

2023/2024

Available from 04/18/2024

US-Summery
US-Summery 🇮🇹

4.1

(22)

937 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C. Conn, R. McLean,
Problem solving final exam guide
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Problem solving final exam guide and more Summaries Physics in PDF only on Docsity!

C. Conn, R. McLean,

Problem solving final exam guide

FINALS EXAM STUDY GUIDE

Algorithm

  • Methodical step-by-step procedure to perform a task Task decomposition
  • Process of breaking a complex task into smaller parts Statement
  • Program instruction, consists of a series of statements Argument
  • Any piece of data that is passed into a function when it is called Parameter
  • Variable that receives an argument Expression
  • Code that returns a value, a * b = 10 Variables
  • Named references to values stored by the interpreter String literal
  • Text endorsed in quotes Newline character
  • \n, within a string literal Type
  • Determines how a value can behave Assignment operator
  • = Identity
  • A unique identifier that describes the object, also called name Keywords
  • reserved words that are already in Python

Loop variable

  • Variable used to count the number of iterations Range
  • range(5) - > 0- 4
  • range(0,5) - > 0- 4
  • range(0,5) - > 0 , 1 , 2 , 3 , 4
  • range(0,5,2) - > 0 , 2 , 4
  • range(5,0,-1) - > 5 , 4 , 3 , 2 , 1
  • range(5,0,-2) - > 5 , 3 , 1 For loop
  • Number of iterations is computable, looking for a specific # of iterations While loop
  • Checking the truth value Nested loop
  • Loop that appears as part of the body of another loop Break
  • Causes an immediate jump to the while / for loop reader statement Return statement
  • Used to return one output value None
  • Special keyword that indicates no value Pass
  • Placeholder, performs no operation Index
  • Position of a character, starts from 0, use [] String concatenation
  • “New” + “York”

Slice notation

  • str [ 0 : 2 ] - > value @ 0 , value @ 1
  • str [ 8 : ] - > value @ 8 until value @ end
  • str [ : - 1] - > all but the last character
  • str [ : ] - > everything Replace
  • replace (old , new)
  • replace (old , new , count) Find
  • find(x) - > returns position of first occurence
  • find(x , start) - > returns position but begins at start
  • find(x , start , end) - > returns position but within start and end Count
  • count(x) - > returns the number of times it occurs Strip
  • str.strip(a) - > return a copy with all a remove List
  • Container that contains references, [] Element
  • Item in a list, can be any type Append
  • .append(x) - > adds x to the end of the list Insert
  • .insert(i , x) - > inserts x in the specific i indicated Pop
  • .pop() - > removes the last item of the list
  • .pop(1) - > removes the item in index 1 Remove
  • .remove(‘abc’) - > removes the first element whose value is ‘abc’

my_list[start : end : stride] Tuples

  • Immutable, () Unpacking tuples
  • me = (‘Alex’ , “Burton” , 19) - > (first name , last name , age) Lists w/ tuples
  • people = [(“Alex” , 19) , (“Eva” , 20)]
  • student_name , age = people[1] Dictionary
  • Another type of container object, {}
  • Lists are associated w/ index, dictionaries are associated w/ key {key : value}
  • Keys have to match exactly Indexing dictionary
  • contacts = {“Alan‘ : “19” , “Patrick” : “20”}
  • ages[“Alan”] - > “19” Adding to a dictionary
  • ages[“Liam”] = “20” Overwriting a key
  • If key already exists in a dictionary, then the value is changed .values()
  • Checks all the values in the dictionary
  • For phone_number (value) in contacts.keys(): (name of dictionary) Nested dictionaries
  • dictionary = {“Neal” : {“office” : “vec 405” , “dept” : “cecs”}}
  • dictionary [“Neal”] [“office”] PRACTICE MCQs VARIABLE NAMES
  1. Is Python case sensitive when dealing with identifiers? a. yes b. no c. machine dependent d. none of the mentioned i. a) - > Case is always significant.
  2. What is the maximum possible length of an identifier? a. 31 characters b. 63 characters c. 79 characters d. none of the mentioned i. d) - > Identifiers can be of any length.
  3. Which of the following is invalid? a. _a = 1 b. __ a = 1 c. str __ = 1 d. none of the mentioned i. d) - > All the statements will execute successfully but at the cost of reduced readability.
  4. Which of the following is an invalid variable? a. my_string_ b. 1st_string c. Foo d. _ i. b) - > Variable names should not start with a number.
  5. Why are local variable names beginning with an underscore discouraged? a. they are used to indicate private variables of a class b. they confuse the interpreter c. they are used to indicate global variables d. they slow down execution i. a) - > As Python has no concept of private variables, leading underscores are used to indicate variables that must not be accessed from outside the class.
  6. Which of the following is not a keyword?