07 slide presenation - Engineering Computation: Tutorial 07...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Engineering Computation: Tutorial 07 Problem Solving with Computing, using the Python Language Questions from Week 06? Programming Exercises from Zelle textbook 1 pg. 228 # 3, 5, 11, 16, 17. 2 Whats in your toolbox? Print statement, string literals Basic calculator, integer division Variables Built-in functions Math library functions Non-branching programs Branching programs Python lists For loops Nested for loops Strings Converting between number system using Python Matplotlib Algorithms File Processing Graphics Functions Scope of Variables Comments 3 Todays Topics: 1 Complex Conditions 2 Testing 3 Debugging 4 Exception Handling 4 Recap: If Statements >>> from graphics import * >>> def pnAbsSlope(p1,p2): ... x1=p1.getX() ... y1=p1.getY() ... x2=p2.getX() ... y2=p2.getY() ... slope = (float(y2) - y1) / (float(x2) - x1) ... if slope > 0: ... print "Positive Slope" ... else: ... print "Negative Slope" ... slope = -slope ... return slope ... >>> 5 Recap: If Statements >>> from graphics import * >>> def pnAbsSlope(p1,p2): ... x1=p1.getX() ... y1=p1.getY() ... x2=p2.getX() ... y2=p2.getY() ... slope = (float(y2) - y1) / (float(x2) - x1) ... if slope > 0: ... print "Positive Slope" ... else: ... print "Negative Slope" ... slope = -slope ... return slope ... >>> slope = pnAbsSlope(Point(0,0), Point(0,4)) Negative Slope >>> 5 Recap: If Statements >>> from graphics import * >>> def pnAbsSlope(p1,p2): ... x1=p1.getX() ... y1=p1.getY() ... x2=p2.getX() ... y2=p2.getY() ... slope = (float(y2) - y1) / (float(x2) - x1) ... if slope > 0: ... print "Positive Slope" ... else: ... print "Negative Slope" ... slope = -slope ... return slope ... >>> slope = pnAbsSlope(Point(0,0), Point(0,4)) Negative Slope >>> slope >>> 5 Point to Ponder What if we want our slope calculator to output Zero Slope? 6 Recap: If Statements >>> from graphics import * >>> def pnAbsSlope(p1,p2): ... x1=p1.getX() ... y1=p1.getY() ... x2=p2.getX() ... y2=p2.getY() ... slope = (float(y2) - y1) / (float(x2) - x1) ... if slope > 0: ... print "Positive Slope" ... elif slope < 0: ... print "Negative Slope" ... slope = -slope ... else: ... print "Zero Slope" ... ... return slope ... >>> 7 Which branch(es) will be run? >>> def doIt(i): ... if i > 5: ... print "greater than 5" ... elif i > 2: ... print "greater than 2" ... elif i > -25: ... print "greater than -25" ... else: ... print "a very small number" ... >>> doIt(30) 8 Which branch(es) will be run? >>> def doIt(i): ... if i > 5: ... print "greater than 5" ... elif i > 2: ... print "greater than 2" ... elif i > -25: ... print "greater than -25" ... else: ... print "a very small number" ... >>> doIt(30) 8 Which branch(es) will be run? >>> def doIt(i): ... if i > 5: ... print "greater than 5" ... elif i > 2: ... print "greater than 2" ... elif i > -25: ... print "greater than -25" ... else: ... print "a very small number" ......
View Full Document

Page1 / 86

07 slide presenation - Engineering Computation: Tutorial 07...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online