720 likes | 738 Views
Get an overview of the course syllabus and learn about computer science principles, programming, and problem-solving in this introductory class. Stay updated with important announcements and ground rules. Practice expressions in Python and understand programming fundamentals.
E N D
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 Name of Class is… Intro. to Computer Science I
REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? Computer scienceinot the study ofprogramming
REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? Computer sciencestudy ofsolvingproblems
REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? Computer engineeringstudy ofsolvingproblems
REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW What are We Studying? "Programmingis awaythat we create[…] solutions"
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
REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW REVIEW Learning is active Slides & videos posted, but…YOUR notesalways better
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
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
Today's Plan Ground rules Expressions Demo: expressions in Python
Today's Plan Ground rules Expressions Demo: expressions in Python
Ground Rules Change is inevitable
Ground Rules Change is inevitable Programmers adapt to survive and thrive
Ground Rules Programming fundamentals Specific details differbetween programming languages General principles commonto all programming languages
Ground Rules Programming fundamentals • Specific details differbetween programming languages
Ground Rules Correct not complete Everything we tell you should be correct* But impossible to tell you everything * "too err is human"
Ground Rules Knowledge and skill will grow Will revisit topics & add to our knowledge over term • Skills can only develop with practice
Ground Rules • Knowledge and skill will grow • Skills can only develop with practice
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
Today's Plan Ground rules Expressions Demo: expressions in Python
Expressions • Piece(s) of code that evaluate to a value
Expressions • Piece(s) of code that evaluate to a value Examples: 3 + 5 3 5 3
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
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
Expressions • Piece(s) of code that evaluate to a value Can draw (visualize) compound expression evaluation as tree + 3 5
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
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")
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
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
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
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
Compound Expressions Common binary operators
Multi-Operator Expression Is 2 * 8 + 5a valid expression?
Multi-Operator Expression Is 2 * 8 + 5 a valid expression?Yes!
Multi-Operator Expression Is 2 * 8 + 5 a valid expression?Yes! Has same basic structure of most compound expressions: operator expression expression
Multi-Operator Expression Is 2 * 8 + 5 a valid expression?Yes! Has same basic structure of most compound expressions: operator operator expression expression expression
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
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
Expressions Order of Operations Follows expected rules from mathematics:Inside parenthesesExponentiationMultiplication & divisionAddition & subtraction 6 - 3 + (1 + 4 * 5)evaluates to 24
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
More Expressions String (str) evaluation Expressions evaluated to produce their values Simple expression "hello"has value "hello" Expression"hello" + "world"has value "helloworld"
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
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
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
Operator Key Concept +behavior changes: Adds two numbers Combinestwo strings
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
How Python Adds Data Types Determines Actions Expression "4" + "3"has value "43" Expression 4 + 3has value 7 Expression 4 + "3"has value…