1 / 71

CSE 115

CSE 115. Introduction to Computer Science I. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW. Review. Read through syllabus (link on course website) Academic Integrity is important! Sign up for TopHat. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW.

currys
Télécharger la présentation

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. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Review • Read through syllabus • (link on course website) • Academic Integrity is important! • Sign up for TopHat

  3. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Name of Class is… Intro. to Computer Science I

  4. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? Computer scienceinot the study ofprogramming

  5. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? Computer sciencestudy ofsolvingproblems

  6. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? Computer engineeringstudy ofsolvingproblems

  7. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? "Programmingis awaythat we create[…] solutions"

  8. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Note about posted slides Postingsmay contain slides not presented in lecture Done when we want posted slides to include:Questions that came up during lecture;Content presented on whiteboard;Improvements to how material presented

  9. REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Learning is active Slides & videos posted, but…YOUR notesalways better

  10. Announcements • UBInfinite open and ready for studentsCreate your account & start working now after class No labs or recitations this weekRooms will be dark and unstaffed Ungraded labs and recitations next weekOpportunity to meet TAs & get set up Graded work start week of Sept. 9thWork done entirely in room & part of grade

  11. Announcements • Must bring UB ID to each labTAs must swipe ID to enable access to activity • Labs completed using lab machines • Lab exams, midterm, & final are closed-note

  12. Today's Plan Ground rules Expressions Demo: expressions in Python

  13. Today's Plan Ground rules Expressions Demo: expressions in Python

  14. Ground rules

  15. Ground Rules Change is inevitable

  16. Ground Rules Change is inevitable Programmers adapt to survive and thrive

  17. Ground Rules Programming fundamentals Specific details differbetween programming languages General principles commonto all programming languages

  18. Ground Rules Programming fundamentals • Specific details differbetween programming languages

  19. Ground Rules Correct not complete Everything we tell you should be correct* But impossible to tell you everything * "too err is human"

  20. Ground Rules Knowledge and skill will grow Will revisit topics & add to our knowledge over term • Skills can only develop with practice

  21. Ground Rules • Knowledge and skill will grow • Skills can only develop with practice

  22. Ground Rules Identification Use this logo when showing Python code JavaScript code with logo so can identify it When mixing languages, logo placed next to the code segment Logo placed in bottom-right corner, when used for entire slide

  23. Today's Plan Ground rules Expressions Demo: expressions in Python

  24. Expressions • Piece(s) of code that evaluate to a value

  25. Expressions • Piece(s) of code that evaluate to a value Examples: 3 + 5 3 5 3

  26. Expressions • Piece(s) of code that evaluate to a value Examples: 3 + 5 3 5 3 3 is a (simple) expression 5 is a (simple) expression 3 is a (simple) expression

  27. Expressions • Piece(s) of code that evaluate to a value 3+5is a (compound) expression.Program applies operator (in this case: +)to subexpressions, 3 and 5, to create larger expression 3+5 3 5 3 3 is a (simple) expression 5 is a (simple) expression 3 is a (simple) expression

  28. Expressions • Piece(s) of code that evaluate to a value Can draw (visualize) compound expression evaluation as tree + 3 5

  29. Expressions Simple • Atomic (cannot decompose)(cannot have subexpressions) Examples: 3 17 Compound Must be able to decompose(must have subexpressions) Examples: 3 + 5 -12 * 17

  30. Simple Expressions • 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")

  31. Simple Expressions • 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") Pythontypes matter! • str"4"unusable as numberint4unusable as text

  32. Simple Expressions • 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') Pythontypes matter! • str'4'unusable as numberint4unusable as text

  33. Simple Expressions • 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') Punctuationmatters! • '4"unusable"4'unusable also

  34. Compound Expressions Each compound expression contains: two*subexpressions; AND At least one operator Already familiar applying binaryoperator(has 2 subexpressions) e.g., Binary subtraction operator: 43 – 5Binary addition operator: 12 + 6

  35. Compound Expressions Common binary operators

  36. Multi-Operator Expression Is 2 * 8 + 5a valid expression?

  37. Multi-Operator Expression Is 2 * 8 + 5 a valid expression?Yes!

  38. Multi-Operator Expression Is 2 * 8 + 5 a valid expression?Yes! Has same basic structure of most compound expressions: operator expression expression

  39. Multi-Operator Expression Is 2 * 8 + 5 a valid expression?Yes! Has same basic structure of most compound expressions: operator operator expression expression expression

  40. Multi-Operator Expression Is 2 * 8 + 5 a valid expression?Yes! Has same basic structure of most compound expressions: + "Top level" expression adds values of smaller expressions, 2 * 8and 5. 2 * 8evaluates to 1616 + 5evaluates to 21 * 5 2 8

  41. Multi-Operator Expression Order of OperationsLanguages' precedence ruleshelp evaluate compound expressions Usually match order of operations familiar from arithmetic Without rules,2 * 8 + 5could instead be * "Top level" expression multiples values of smaller expressions, 2and 8 + 5. 8 + 5evaluates to 132 * 13evaluates to 26 2 + 8 5

  42. Expressions Order of Operations Follows expected rules from mathematics:Inside parenthesesExponentiationMultiplication & divisionAddition & subtraction 6 - 3 + (1 + 4 * 5)evaluates to 24

  43. Expressions Evaluation Expressions evaluated to produce their values Expression 3 has value 3 Expression 3 + 5has value 8 Expression 10 / 3has value 3.3333333333 Expression 10 // 3has value 3 Expression 5 ** 2has value 25

  44. More Expressions String (str) evaluation Expressions evaluated to produce their values Simple expression "hello"has value "hello" Expression"hello" + "world"has value "helloworld"

  45. More Expressions String (str) expressions Expressions evaluated to produce their values Expression "hello"has value "hello" Expression "hello" +"world"has value "helloworld" For str values,+concatenates data

  46. More Expressions • String (str) expressions • Expressions evaluated to produce their values • Expression "hello"has value "hello" Expression "hello" + "world"has value "helloworld" +does NOT add spaces;only job is to concatenate

  47. More Expressions • String (str) expressions • Expressions evaluated to produce their values • Expression "hello"has value "hello" Expression "hello " + "world"has value "hello world" If result should include a space,must add it yourself

  48. Operator Key Concept +behavior changes: Adds two numbers Combinestwo strings

  49. 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

  50. How Python Adds Data Types Determines Actions Expression "4" + "3"has value "43" Expression 4 + 3has value 7 Expression 4 + "3"has value…

More Related