An Introduction To Programming Using Pythondavid I Schneideran Intro ✓ Solved
An Introduction to Programming Using Python David I. Schneider An Introduction to Computing and Problem Solving Lesson 1 © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Questions and Answers • How do we communicate with the computer? – Programming languages • How do we get computers to perform complicated tasks? – Tasks are broken down into a sequence of instructions • Why Python? – Powerful, easy to download, write and read © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Questions and Answers • How did the language Python get its name? – Named for the British comedy group Monty Python (really!) • Book uses the editor IDLE to create programs. How did IDLE get its name? – Stands for Integrated DeveLopment Environment • What is an interpreted language? – Uses an interpreter, translates high-level language one statement at a time into machine language and then runs © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Questions and Answers • What are the meanings of the terms “programmer†and “userâ€? – Programmer: a person who solves problems by writing programs on a computer – User: any person who runs a program • What is the meaning of the term “codeâ€? – Python statements that the programmer writes © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Questions and Answers • Are there certain characteristics that all programs have in common? – Input, processing, output • What are the meanings of the terms “hardware†and “softwareâ€? – Hardware: physical components of the computer – Software: the programs © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Questions and Answers • How are problems solved with a program? – Step-by-step procedure devised to process given data and produce requested output. • What is a zero-based numbering system? – Numbering begins with zero instead of one • Prerequisites to learning Python? – Be familiar with how folders and files are managed © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Questions and Answers • What is an example of a program developed in this textbook? © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. FIGURE 1.1 A possible output for a program in Lesson 2. Questions and Answers • How does the programmer create such a program? – About ten lines of code that search a text file named USpres.txt and extract the requested names. © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Questions and Answers • What conventions are used to show keystrokes? – key1+key2 means “hold down key1 and then press key2†• Ctrl+C places selected material into the Clipboard – key1/key2 means “Release key1 and then press key2†• Alt/F opens the FILE menu on a menu bar. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Questions and Answers • How can the programs for the examples in this textbook be obtained? – See the preface for information • Where will new programs be saved? – Create a special folder to hold your programs • Where can I research questions I have about Python? – Documentation at © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Program Development Cycle © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. FIGURE 1.2 The problem solving process. Program Planning 1. Analyze: Define the problem.
2. Design: Plan the solution to the problem. 3. Code: Translate the algorithm into a programming language. 4.
Test and correct: Locate and remove any errors in the program. 5. Complete the documentation: Organize all the material that describes the program. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Programming Tools • Algorithms • Flowcharts • Pseudocode • Hierarchy charts © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Algorithm Development Algorithm to determine number of stamps for a letter • Rule of thumb: 1 stamp for every 5 sheets of paper 1. Request sheets of paper 2. Divide by 5 3. Round quotient up to next whole number 4.
Reply with number of stamps © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Problem Solving for Stamps © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. FIGURE 1.3 The problem solving process for the stamp problem.
Flowcharts © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Example Flowchart © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. FIGURE 1.4 Flowchart for the postage-stamp problem.
Pseudocode • Abbreviated plain English version of actual computer code • Symbols used in flowcharts replaced by English-like statements • Allows programmer to focus on steps required to solve problem © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Example Pseudocode © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. FIGURE 1.5 Pseudocode for the postage stamp problem.
Hierarchy Chart • Shows the overall program structure • Depict organization of program, omit specific processing logic • Describe what each part, or module, of the program does • Each module subdivided into a succession of submodules © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Example Hierarchy Chart © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. FIGURE 1.6 Hierarchy chart for the postage-stamp problem.
Decision Structure © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. FIGURE 1.7 Pseudocode and flowchart for a decision structure. Direction of Numbered NYC Streets Algorithm • Problem: Given street number of one-way street in New York City, decide direction of street, either eastbound or westbound. • Discussion: There is a simple rule to tell the direction of a one-way street in New York City: Even-numbered streets run eastbound. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Direction of Numbered NYC Streets Algorithm • Input: Street number. • Processing: Decide if the street number is divisible by 2. • Output: “Eastbound†or “Westboundâ€. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Direction of Streets Algorithm FIGURE 1.8 Flowchart for the numbered New York City streets problem. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Direction of Streets Algorithm FIGURE 1.9 Pseudocode for the numbered New York City streets problem. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Direction of Streets Algorithm FIGURE 1.10 Hierarchy chart for the numbered New York City streets problem. Repetition Structure • A programming structure that executes instructions many times – Repetition structure – Looping structure • Need a test (or condition) to tell when the loop should end – Check condition before each pass through loop © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Direction of Streets Algorithm FIGURE 1.11 Pseudocode and flowchart for a loop. Class Average Algorithm • Problem: Calculate and report the average grade for a class. • Discussion: Average grade equals sum of all grades divided by number of students. – Need loop to read and then add (accumulate) grades for each student in class. – Inside the loop, we also need to total (count) number of students in class. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Class Average Algorithm • Input: Student grades. • Processing: Find the sum of the grades; count the number of students; calculate average grade = sum of grades / number of students. • Output: Average grade © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Class Average Algorithm FIGURE 1.12 Flowchart for the class average problem. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Class Average Algorithm FIGURE 1.13 Pseudocode for the class average problem. © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Class Average Algorithm FIGURE 1.14 Hierarchy chart for the class average problem. How to get Python compiler • Go to: • Follow instruction’s on how to install python on your favorite Operating system. • If this is your first time using a programming compiler you are encourage to do the tutorials. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Starting IDLE • Windows: Invoke with double click of • MAC: Open Finder, select Applications, select the Utilities folder, select Terminal, and then enter IDLE at the prompt • LINUX and UNIX: usually be found at /usr/bin/idle3 © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Starting IDLE FIGURE 1.16 The Python shell. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Starting IDLE FIGURE 1.17 The Python shell after the expression 2 + 3 has been evaluated. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Starting IDLE FIGURE 1.18 The Python shell after the statement print(“hello CS625 Class ") has been executed. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. A Python Code Editor Walkthrough FIGURE 1.19 The File drop-down list. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. A Python Code Editor Walkthrough FIGURE 1.20 The code editor window generated after New Window is clicked on. © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. A Python Code Editor Walkthrough FIGURE 1.21 The code editor window containing a three-line Python program. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. A Python Code Editor Walkthrough FIGURE 1.22 A Save As dialog box. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
A Python Code Editor Walkthrough FIGURE 1.23 The code editor window containing a three-line Python program. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. A Python Code Editor Walkthrough FIGURE 1.24 Press the F5 key to execute. The outcome of the Python program in Fig. 1.22. © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. A Python Code Editor Walkthrough FIGURE 1.25 A Save message box. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. An Open-a-Program Walkthrough FIGURE 1.26 An Open dialog box. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Click on desired program An Open-a-Program Walkthrough FIGURE 1.27 Example 10 of Section 3.4. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. An Open-a-Program Walkthrough FIGURE 1.28 Request for input from Example 10 of Section 3.4. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. An Open-a-Program Walkthrough FIGURE 1.29 Complete output for Example 10 of Section 3.4. © 2016 Pearson Education, Inc., Hoboken, NJ.
All rights reserved. Block-Structure Figure 1.30 Example 10 of Section 3.4. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. The File Drop-down Menu FIGURE 1.31 The File drop-down menu. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Paper for above instructions
Programming has become an indispensable skill in today's technology-driven world. “An Introduction to Programming Using Python” by David I. Schneider provides an accessible entry point for aspiring programmers. In this essay, we will explore fundamental concepts presented in the book regarding programming, specifically through Python, a language credited for its simplicity and versatility.
Communication with Computers
Programming can be defined as the process of turning human intentions into a format that computers can understand. This is achieved through programming languages such as Python. Schneider emphasizes that programming languages serve as a bridge between humans and machines (Schneider, 2016). Programmers communicate with computers by writing code—an assemblage of logical statements and instructions that can be interpreted by the machine.
Why Choose Python?
Python is favored for its simplicity, readability, and vast community support. As highlighted in Schneider's text, the language was named after the British comedy group Monty Python, which reflects its creator’s intent to make programming fun (Schneider, 2016). Additionally, Python has been acclaimed for its wide application ranging from web development to data analysis and artificial intelligence.
Features of Python
- Interpreted Language: Python is an interpreted language; it executes code line by line, allowing for easier debugging and interactive programming (Lutz, 2013).
- Readable Syntax: The clear syntax of Python enhances its readability, reducing the learning curve for beginners (Beazley, 2016).
- Extensive Libraries: Python boasts numerous libraries, which enable programmers to perform complex tasks without reinventing the wheel (McKinney, 2010).
Program Development Cycle
The program development cycle, as explained in Schneider's work, consists of five key stages:
1. Analysis: Understanding and defining the problem.
2. Design: Planning the solution through algorithms, flowcharts, or pseudocode.
3. Code: Translating the design into Python programming constructs.
4. Test and Correct: Debugging to ensure the program operates as intended.
5. Documentation: Compiling all relevant information regarding the program for future reference (Schneider, 2016).
This cyclical approach allows programmers to methodically tackle problems and create effective software solutions.
Problem Solving Techniques
Effective problem-solving is at the core of programming. Schneider illustrates this with various methods such as flowcharts and pseudocode. Flowcharts visually depict processes and decisions, while pseudocode presents algorithm outlines in human-readable form, stripping away syntax specifics (Schneider, 2016).
Example: Stamp Counting Algorithm
One simple algorithm Schneider presents involves determining the number of stamps required to send a letter. The steps include requesting the number of sheets, dividing by five (since one stamp is needed for every five sheets), rounding up, and finally displaying the number of required stamps (Schneider, 2016). This illustrates the sequences involved in programming — from input to processing to output.
Control Structures
Control structures are essential constructs in programming that direct the flow of the program:
- Decision Structures: These structures enable branching logic, allowing the programmer to choose different paths based on conditions (Schneider, 2016). For instance, in Schneider's example of New York City street direction, one can ascertain whether to categorize the street as east or west based on whether the street number is even or odd.
- Repetition Structures: Also known as loops, these structures allow the execution of a block of code multiple times until a condition is met (Schneider, 2016). An example in the book calculates a class average by summing up students' grades in a loop until all entries are processed.
Using Python: Getting Started
Initiating one’s journey in Python programming requires setting up a working environment. Schneider advises new users to download Python and familiarize themselves with its Integrated Development Environment (IDLE) (Schneider, 2016). This tool facilitates code writing, execution, and debugging.
Simple Python Program Example
A simple Python program can be as effortless as using print statements to display output. For instance, to greet the user, one could write:
```python
print("Hello, CS625 Class")
```
The simplicity of this example exemplifies Python's straightforward syntax and makes it suitable for beginners (Lutz, 2013).
Conclusion
David I. Schneider's "An Introduction to Programming Using Python" emphasizes the captivating journey of programming. Python’s flexibility, combined with a structured approach to program development and problem-solving techniques, makes it an excellent choice for those venturing into the world of coding. This book lays a robust foundation for understanding programming and instills confidence in learners, ensuring they are well-equipped to continue exploring and developing code.
References
1. Beazley, D. (2016). Python Essential Reference. Addison-Wesley.
2. Lutz, M. (2013). Learning Python. O'Reilly Media.
3. McKinney, W. (2010). Python for Data Analysis. O'Reilly Media.
4. Schneider, D. I. (2016). An Introduction to Programming Using Python. Pearson Education.
5. Zelle, J. (2010). Python Programming: An Introduction to Computer Science. Franklin, Beedle & Associates Inc.
6. Downey, A. (2012). How to Think Like a Scientist. Green Tea Press.
7. Sweigart, A. (2015). Automate the Boring Stuff with Python. No Starch Press.
8. Grus, J. (2019). Data Science from Scratch: First Principles with Python. O'Reilly Media.
9. van Rossum, G., & Drake, F. L. (2009). Python 3 Reference Manual. CreateSpace Independent Publishing Platform.
10. VanderPlas, J. (2016). Python Data Science Handbook. O'Reilly Media.