1 / 72

CSE 115

CSE 115. Introduction to Computer Science I. UBInfinite Requirements. This week: Lab activity 5 Module 3 – Writing Files Module 3 – Web Front End Module 2 – Reading Files Next week: Lab activity 6 Module 3 – Writing Files Module 3 – Web Front End. Exam Rules 1. Closed book

wdorothy
Download Presentation

CSE 115

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE 115 Introduction to Computer Science I

  2. UBInfinite Requirements • This week: Lab activity 5 • Module 3 – Writing Files • Module 3 – Web Front End • Module 2 – Reading Files Next week: Lab activity 6 Module 3 – Writing Files Module 3 – Web Front End

  3. Exam Rules 1 • Closed book • Closed notes • Closed neighbor • Absolutely no electronics

  4. Thursday examroom assignments

  5. Exam Rules 2 • Bring your UB ID CardNo arrivals after first 30 minutesNo departures in first 30 minutes • Seating chart will be posted on exam room door • Name pre-printed on exams;Double-check name to insure seat correct

  6. Exam Rules 3 • Only test, ID card, pencil/pen & erasers out NOTHING ELSE • Bags & jackets go on floor under your seatPhones & electronics IN bags • No hats worn (unless for religious reasons) • Visit the facilities before the exam starts.The exam is only an hour long…

  7. Exam Advice • Start by reading through examDo easy questions firstIf you get stuck, move on and and return • Read question completely before answeringOnly answer the question being asked • Small syntax problems will not be penalized • Cannot answer content questionsRemember: this is YOUR test

  8. Module 1 topics • Expressions (e.g. literals, variables, compound expressions)Operators (numeric, string, boolean, relational)Assignment statementFunction calls (arguments)Function definitions (parameters)Flow of control (sequences, conditionals) • Python syntax • Vocabulary • UBInfinite + lecture examples + TopHat + lab activities

  9. Module 2 topics • JavaScript syntax • Arrays (JS) & Lists (PY) • Objects (JS) & Dictionaries (PY) • Loops (JS: for…in, for…of) Loops (PY: for…in, range) • Accumulator code pattern (various examples) • File reading • CSV library • Vocabulary • UBInfinite + lecture examples + TopHat + lab activities

  10. TopHat

  11. jsonStr = # Code evaluated to a JSON str pyVar = json.loads(jsonStr) Pick Correct Answer Does where jsonStr's data originated matter? Yes! Argument to json.loads() must be tagged as coming from urllib library Yes! Argument to json.loads() must be tagged as from Internet, but any library okay Maybe.Argument to json.loads() just needs to have value whose type is Internet_str No! Computers just follow instructions, so any str of JSON valid argument to json.loads() None of the above answers are correct

  12. jsonStr = # Code evaluated to a JSON str pyVar = json.loads(jsonStr) Pick Correct Answer Convince Your Neighbor Your Answer Is Correct Does where jsonStr's data originated matter? Yes! Argument to json.loads() must be tagged as coming from urllib library Yes! Argument to json.loads() must be tagged as from Internet, but any library okay Maybe.Argument to json.loads() just needs to have value whose type is Internet_str No! Computers just follow instructions, so any str of JSON valid argument to json.loads() None of the above answers are correct

  13. jsonStr = # Code evaluated to a JSON str pyVar = json.loads(jsonStr) Pick Correct Answer Does where jsonStr's data originated matter? Yes! Argument to json.loads() must be tagged as coming from urllib library Yes! Argument to json.loads() must be tagged as from Internet, but any library okay Maybe.Argument to json.loads() just needs to have value whose type is Internet_str No! Computers just follow instructions, so any str of JSON valid argument to json.loads() None of the above answers are correct

  14. jsonStr = # Code evaluated to a JSON str pyVar = json.loads(jsonStr) Pick Correct Answer Does where jsonStr's data originated matter? Yes!Argument to json.loads()must be tagged as coming from urlliblibrary Yes!Argument to json.loads() must be tagged as from Internet, but any library okay Maybe.Argument to json.loads()just needs to have value whose type isInternet_str No! Computers just follow instructions, so any str of JSON valid argument to json.loads() None of the above answers are correct JSON used bycomputersto share dataover Internet.Why else have strwith JSON?

  15. jsonStr = # Code evaluated to a JSON str pyVar = json.loads(jsonStr) Pick Correct Answer Does where jsonStr's data originated matter? Yes!Argument to json.loads()must be tagged as coming from urlliblibrary Yes!Argument to json.loads() must be tagged as from Internet, but any library okay Maybe.Argument to json.loads()just needs to have value whose type isInternet_str No! Computers just follow instructions, so any str of JSON valid argument to json.loads() None of the above answers are correct Why else have strwith JSON?

  16. jsonStr = # Code evaluated to a JSON str pyVar = json.loads(jsonStr) Pick Correct Answer Does where jsonStr's data originated matter? Yes!Argument to json.loads()must be tagged as coming from urlliblibrary Yes!Argument to json.loads() must be tagged as from Internet, but any library okay Maybe.Argument to json.loads()just needs to have value whose type isInternet_str No! Computers just follow instructions, so any str of JSON valid argument to json.loads() None of the above answers are correct Why else have strwith JSON?

  17. jsonStr = # Code evaluated to a JSON str pyVar = json.loads(jsonStr) Pick Correct Answer Does where jsonStr's data originated matter? Yes! Argument to json.loads() must be tagged as coming from urllib library Yes! Argument to json.loads() must be tagged as from Internet, but any library okay Maybe. Argument to json.loads() just needs to have value whose type is Internet_str No! Computers just follow instructions, so any str of JSON valid argument to json.loads() None of the above answers are correct

  18. Questions

  19. Python Literals (& Types) • Numeric literals int (e.g.,4037, 4_037) float (e.g.3.1415, 6.02214e23, 6.02_214e23, 4.0) • Boolean literals False, True • (String) Textliterals(either single or double quote okay) str (e.g."This is str", 'Also str', "A", "4")

  20. JavaScript Literals(& Types) • Numeric literalsNumber (e.g. 99 , 3.1415, 6.02214e23, -35) • Boolean literalsfalsetrue • Text ("string") literalsString (e.g. "This is text",'Also text','A',"A")

  21. Simple vs Compound expressions statements values compound 13.79 * 12 compound if { … } else { … } compound [ 42, 17, -318 ]{'nyc':55,'bos':37} ('a','tuple') simple 13.79 simple x = e simple 13.79

  22. JavaScript "Types"

  23. Python Operators

  24. JavaScript Operators

  25. Writing a Compound Expression Subgoals • exp1) Determine the left-hand side of the expression • a) Write the left-hand subexpressionb) Determine the type for the value this subexpression evaluates to • exp2) Write the operator • exp3) Determine the right-hand side of the expression • a) Write the right-hand subexpressionb) Determine the type for the value this subexpression evaluates to • exp4) Verify operator valid for subexpressions' types

  26. Variable Namethat has beenassigned avalue

  27. Writing an Assignment Subgoals • assign1) Write the name of the variable • assign2) Write the assignment operator • assign3) Write the expression whose value will be assigned to the variable

  28. Writing an Assignment Subgoals • assign0) If first use of variable in function, write let keyword • assign1) Write the name of the variable • assign2) Write the assignment operator • assign3) Write the expression whose value will be assigned to the variable

  29. Variables Assignment let name=expression assign1) namewritten on left-handsideof assignment operator assign3) expressionwritten onright-handsideof assignment operator assign2) write the assignment operator assign0) letneeded for first useof variable in JavaScript function

  30. String Processing • JavaScript also has its own String functions

  31. Writing a Function Call Expression Subgoals • fc1) Write the function name • fc2) Write the argument lista) Start the argument list with an open parenthesisb) For each function input in the order they are listed, write the expression whose value is used for that inputc) Write a comma between each pair of argumentsd) End the argument list with a close parenthesis

  32. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Function Calls Examples • pow(3,2) • min(16/3,4) • x = -6abs(x) • print( "Hi there!" ) fc1) Write the functionname fc2)Write the argumentlist

  33. Function Calls Examples • Math.pow(3 , 2); • Math.min(10/3 , 4 ); • let x = "-6";let y = isFinite(x + 3); • console.log( "Hi there!"); fc1) Write the functionname fc2) Write the argumentlist

  34. Writing a Function Subgoals • fd1) Write comment describing result of evaluating function call (or what function does, if not returning a value) • fd2) Write the function header & delimitersa) Write the def keywordb) Write the function's namei) Choose name reflecting function's SINGLE purposec) Write the parameter list of the function's input(s)i) Choose name(s) expressing value of eachd) Write the function delimiter at the end of the header • fd3) Write the function bodya) Parameter(s) are assigned values BEFORE function begins; you should not reassign these valuesb) If returning a value, check that each path through the function body ends at a return whose expression evaluates to that value

  35. Writing a Function Definition Subgoals • fd1) Write comment describing result of evaluating call to this function call (or what function does, if not returning a value) • fd2) Write the function header & delimitersa) Write the function keywordb) Write the function's namei) Choose name reflecting function's SINGLE purposec) Write the parameter list for the function's input(s)i) Choose name(s) expressing value of eachd) Write the function delimiters • fd3) Write the function body inside the delimitersa) Parameter(s) assigned values BEFORE function begins; you should not reassign these valuesb) If call to this function evaluates to a value, make certain that each path through function body ends at a return whose expression evaluates to that value

  36. Defining functions • Function's parts follow from subgoals fd2a-c) header def averageOfThree( x, y, z ) : average = (x + y + z) / 3return average fd2d) delimiters fd3)indented body

  37. Defining functions Functions contain same parts as before fd2a-c) header functionaverageOfThree( x, y, z ) {let average = (x + y + z) / 3; return average; } fd3)body fd2d) delimiters

  38. Defining functions Contain same parts in both languages header def averageOfThree( x, y, z ):average = (x + y + z) / 3 return average; body delimiters header functionaverageOfThree( x, y, z ) {let average = (x + y + z) / 3; return average; } body delimiters

  39. Defining functions

  40. Control flow • Statement execution orderings in program: • Sequence • Selection • Repetition

  41. Writing a Selection Statement Subgoals • sel1) Determine number of distinct execution paths • sel2) Determine the guard expressions that are neededa) For each execution path, write the guard expression specifying conditions when it should be runb) Order guard expression(s) from most-restrictive to least-restrictive • sel3) Use most-restrictive guard expression for first part of selection statementa) Write if header using the most-restrictive guard expressionb) Write the delimiterc) Write if body for that execution path • sel4) For each guard expression remaining, in order of decreasing restrictiveness, write elif sectiona) Write elif header using the guard expressioni) If this is last execution path & run for all remaining cases, replace elif header with elseb) Write the delimiterc) Write each elif or elsebody for that execution path

  42. Writing Compound Selection Statement Subgoals • sel1) Determine number of distinct execution paths • sel2) Determine the guard expressions that are neededa) For each execution path, write the guard expression specifying conditions when it should be runb) Order guard expression(s) from most-restrictive to least-restrictive • sel3) Use most-restrictive guard expression for theifsectiona) Write if header with the most-restrictive guard expression in parenthesisb) Write the delimitersc) Write if body for that execution path inside the delimiters • sel4) For each guard expression remaining, in order of decreasing restrictiveness, write else if sectiona) Write else ifheader with the guard expression in parenthesisi) If this is last execution path & run for all remaining cases, replace else ifheader with elseb) Write the delimitersc) Write else if or elsebody for that execution path inside the delimiters

  43. Selection Statement: if Parts of an if Statement delimeter if keyword guard expression : if (a<b) and (a<c) print('a is the smallest')smallest = a indentation code suite

  44. Selection Statement: if-elif-else Parts of an if-elif-else Statement delimiter if header if (a<b) and (a<c) :print('a is the smallest') smallest = a elif (b<a) and (b<c) : print('b is the smallest') smallest = b else : print('c is the smallest') smallest = c if body elifheader delimiter elif body else header delimiter else body

  45. Selection Statement: if-else Parts of a if-else Statement delimiter if header if ((a < b) && (a < c)) {print('a is the smallest'); smallest = a; } else { print ('a not smallest') } if body delimiter delimiter else body else keyword

  46. Compound Selection Statement Parts of Compound Selection Statement if header if ( (a < b) && (a < c) ) { else if header console.log('a small');sm = a; if body } else if ( (b < a) && (b < c) ) { else if body console.log('b small');sm = b; else header } { else console.log('c small');sm = c; else body }

  47. Selection Statement: if-else if-else Parts of an if-else if-else Statement Keyword change!Python: elif JavaScript: else if if header if ( (a < b) && (a < c) ) { elifheader console.log('a small');sm = a; if body } else if ( (b < a) && (b < c) ) { else if body console.log('b small');sm = b; else header } { else console.log('c small');sm = c; else body }

  48. if-elif-elseControl Flow if (a<b) and (a<c) : print('a small')sm = a elif b < c and x == 2 : print('b, x small') sm = b else : print('weird') z = c print(sm)

  49. Compound Selection Statement Control Flow if ((a < b)&&(a < c)){console.log('a');sm = a; } else if ((b<c)&&(x==2)){console.log('b, x'); sm = b; } else { console.log("odd"); z = c;} console.log(sm)

  50. Loop Statement Subgoal • loop1) Determine the collection whose values you want to process • loop2) Write the loop headera) Write the for keyword • b) Write the name of the loop variable • c) Write the in keyword • d) Write the name of the collection • loop3) Write the ':' delimiter • loop4) Write the loop body, indented consistently • a) The loop variable is assigned a value BEFORE the body is executed: do not assign a value to the loop variable!

More Related