Introduction to Programming in Python Lessons
Total Page:16
File Type:pdf, Size:1020Kb
CLEVELAND INTRODUCTION TO PROGRAMMING IN PYTHON INSTITUTE OF LESSONS 9301C THROUGH 9310C ELECTRONICS Study Guide to accompany Fundamentals of Python – From First Programs Through Data Structures By Kenneth A. Lambert ISBN 10: 1423902181 ISBN 13: 9781423902188 This study guide contains excerpts from the Fundamentals of Python Instructor's resources and the book Fundamentals of Python – From First Programs through Data Structures by Kenneth Lambert © Copyright 2012 Cleveland Institute of Electronics All Rights Reserved / Printed in the United States of America FIRST EDITION / First Printing / March 2012 1 Contents Chat with Your Instructor ......................................................................................................... 3 Chapter 1 - Introduction ............................................................................................................ 4 Chapter 2 - Software Development, Data Types, and Expressions ...................................... 11 Python Lesson 9301C Exam ................................................................................................................. 17 Chapter 3 - Control Statements ................................................................................................. 2 Python Lesson 9302C Exam ................................................................................................................... 7 Chapter 4 - Strings and Text Files........................................................................................... 10 Chapter 5 - Lists and Dictionaries ........................................................................................... 14 Python Lesson 9303C Exam ................................................................................................................. 19 Chapter 6 - Design with Functions .......................................................................................... 21 Python Lesson 9304C Exam ................................................................................................................. 27 Chapter 7 - Simple Graphics and Image Processing ............................................................. 30 Python Lesson 9305C Exam ................................................................................................................. 34 Chapter 8 - Design with Classes .............................................................................................. 37 Python Lesson 9306C Exam ................................................................................................................. 43 Chapter 9 - Graphical User Interfaces.................................................................................... 46 Python Lesson 9307C Exam ................................................................................................................. 50 Chapter 11 - Searching, Sorting, and Complexity Analysis.................................................. 53 Chapter 13 - Collections, Arrays, and Linked Structures .................................................... 58 Python Lesson 9308C Exam ................................................................................................................. 64 Chapter 14 - Linear Collections: Stacks ................................................................................. 67 Python Lesson 9309C Exam ................................................................................................................. 72 Chapter 16 - Linear Collections: Lists .................................................................................... 75 Chapter 18 - Hierarchical Collections: Trees ......................................................................... 81 Python Lesson 9310C Exam ................................................................................................................. 87 Appendix - Quick Quiz Answers ............................................................................................. 90 2 Chat with Your Instructor The Study Guide for Fundamentals in Python is created to provide you with concepts, ideas and pointers for learning about computer programming in Python. Chapter outlines are included followed by topic ideas presented in a chapter-by-chapter format, which include the following: . Quick Quizzes . Additional Resources . Key Terms definitions The topics follow the section-by-section format of the book and are intended to give you a range of ideas for your understanding. Students often learn from investigation of programming topics. For this reason, there are many topic tips throughout this guide. These topic tips may require you to solve a problem, work through a new direction in technology or even attempt to predict the future. All of the topic tips are meant to be thought provoking and to help you apply what you are learning. Each chapter in the Study Guide also includes a set of interesting Additional Resources, which are Web links to topics of interest. Finally, a list of definitions of Key Terms is included for each chapter. Fundamentals in Python – From First Programs through Data Structures, covers many exciting topics, and the staff believes that you will share in the excitement. If you have a technical problem, we recommend the following: First, check the textbook that accompanies the software. Many software products include on-line help. If the answer is not available in the printed materials, try using the Help feature of your software. Feel free to call the instruction department during business hours (8:30 AM to 6 PM Eastern time), Monday through Friday, and Saturday during the weekend hours (8:30 AM to 5 PM Eastern time). Be prepared to describe which lesson you're working on and the problem you're having. Instructional Support Addresses and Phone Numbers Main Support Help Line: (800) 243-6446 or (216) 781-9400 E-mail address: [email protected] Instructional Support is available business hours (Eastern time) Monday through Saturday. Mailing address: Cleveland Institute of Electronics 1776 East 17th Street Cleveland, OH 44114 3 Chapter 1 - Introduction LESSON 9301C At a Glance Lesson Contents Overview Objectives Quick Quizzes Additional Resources Key Terms Chapter Notes Overview Chapter 1 describes the basic features of an algorithm. You learn how hardware and software collaborate in a computer’s architecture. A brief history of computing is provided. Finally, you learn how to compose and run a simple Python program. Objectives After completing this chapter, you will be able to: Describe the basic features of an algorithm Explain how hardware and software collaborate in a computer’s architecture Give a brief history of computing Compose and run a simple Python program Topic Tips Two Fundamental Ideas of Computer Science: Algorithms and Information Processing 4 For a more information on algorithms and their history, read: Topic Tip http://en.wikipedia.org/wiki/Algorithm. The Structure of a Modern Computer System Topic Tip For more on computer software, read: http://en.wikipedia.org/wiki/Software. Quick Quiz 1 1. What is an algorithm? 2. The part of a computer that is responsible for processing data is the ____________________ (CPU). 3. True or False: A program stored in computer memory must be represented in binary digits, which is also known as machine code. 4. A modern ____________________ (GUI) organizes the monitor screen around the metaphor of a desktop, with windows containing icons for folders, files, and applications. A Not-So-Brief History of Computing Systems For a brief history of computer languages and their evolution, read the following: Topic Tip http://www.scriptol.org/history.php. You can find a graph that illustrates Moore’s Law at the following site: Topic Tip http://en.wikipedia.org/wiki/Moore's_law. Quick Quiz 2 1. In the late 1930s, ____________________ (1916–2001), a mathematician and electrical engineer at M.I.T., wrote a classic paper titled “A Symbolic Analysis of Relay and Switching Circuits.” 2. True or False: In the early 1970s, computer scientists realized that a symbolic notation could be used instead of machine code, and the first assembly languages appeared. 3. What is Moore’s Law? 5 4. By the mid 1980s, the ____________________ had grown into what we now call the Internet, connecting computers owned by large institutions, small organizations, and individuals all over the world. Getting Started with Python Programming Python is an interpreted language. If you are familiar with other interpreted Topic Tip languages, compare them to Python. Topic Tip A good Python programming tutorial is available at: http://docs.python.org/tut/. Quick Quiz 3 1. The easiest way to open a Python shell is to launch the ____________________. 2. What is a shell prompt? 3. True or False: In Python, to begin the next output on the same line as the previous one, you can place a colon at the end of the earlier print statement. 4. The term ___________________ refers to the rules for forming sentences in a language. Additional Resources 1. History and evolution of computer languages: www.scriptol.org/history.php 2. Algorithm: http://en.wikipedia.org/wiki/Algorithm 3. Software: http://en.wikipedia.org/wiki/Software 4. Python Tutorial: http://docs.python.org/tut/ Key Terms abacus: An early computing device that allowed users to perform simple calculations by moving beads along wires. abstraction: A simplified view of a task or data structure that ignores complex detail. 6 algorithm(s): A finite sequence of instructions that, when