python08.html - we are past the middle instead of wasting...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
we are past the middle, instead of wasting time in a midterm, lets do a quick quiz every class from now to the end. short and simple. derived from homeworks. what's next: 1. functions 2. recursion 3. strings 4. tuples 5. lists today lets go over two simple exercises from chapter 7: 7.3 7.6 any other exercise from ch 7 or past due exercises you want to do? CHAPTER 8 Functions how to write your own functions and modules def CelsiusToFarenheit (x): return 9 * x / 5 + 32 the code inside the function definition is executed when the function is called Suppose file divideByZero.py contains: def foo (): return 1/0 what happens when you execute: python3 divideByZero.py nothing because 1/0 is not executed the function has not been called what if file divideByZero.py contains: def foo (): return 1/0 foo() what happens now when you execute: python3 divideByZero.py
Image of page 1

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

View Full Document Right Arrow Icon
now it crashes because 1/0 is executed Encapsulation : Wrapping up a piece of useful code in such a way that it can be used without knowledge of the specifics. Black box. Generalization : Making a piece of code useful for a variety of circumstances by controlling it via parameters. Convert x degrees Farenheit to Celsius. Manageability : Dividing a complex program into easy-to-manage chunks. Divide and conquer. Maintainability : Using meaningful names and logical wrappings to make a program better readable and understandable Reusability : Facilitating the transfer of functionalities between programs Recursion : Allowing the use of a technique called "recursion" (Chapter 9). A function calls itself. Some languages do not have loops but achieve the same results using only recursion. wht happens when this code is executed? CelsiusToFarenheit(31) def CelsiusToFarenheit (x): return 9 * x / 5 + 32 this is an error because the function is called before it is defined.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern