Premium Essay

Loops in the Python Programming Language

In: Computers and Technology

Submitted By proyer
Words 265
Pages 2
What are the benefits of using loops in programming? Using the lecture and internet, research examples of loops in python and describe their functions. What is an example of a loop you might see in the real world?
In programming, the use of loops allows a programmer to simplify repetitious tasks with a process that will repeat itself over a series of passed values whether it is form a user passed parameter or a store set of data (for example, pulling a set of data form a database and “looping” through it to perform a series of checks).
The loop function in Python is called using the “for” statement where it will repeat a series of event in a sequence.
The syntax in Python will be: for {element_to_repeat} in {sequence}: Do something here

An example of this could be to output a user’s name on screen in a line break format such as: userName = ‘Paul’ for letter in UserName: print ‘Letter – ‘, letter print ‘That spells ‘, userName

The use of loops in a real world example could be to validate if a series of values falls into a specific range. This may include something such as determining if a set of salaries was higher or lower than a national average. In a previous example, we wrote code that would determine how many years remained in a set of employees until they retired. In my work, I often use loops to run through a set of product serial numbers and determine if each one is in a manufacturer’s warranty or not prior to us shipping

Similar Documents

Premium Essay

Pt1420 Week 3 Programming Assignment

...This week’s programming assignment on how to sort fruits and arrange them in alphabetical order was not easy to do. It took me to do many examples and readings to understand the code in looping structure that is for loop, in the while loop. I have to run module several times, back and forth and carefully observe and do many examples to be able to arrange all the fruit in alphabetical order. What I have learnt so far programming is that, no matter what you code if you do not give the right codes at the right place, you will not get results. Also I learnt something on the concept of a tuple which In mathematics, a tuple is an ordered list of elements. Related to this is an n-tuple, which in set theory is a collection (sequence) of "n" elements....

Words: 562 - Pages: 3

Premium Essay

Hhello

...STARTING OUT WITH Python ® Second Edition This page intentionally left blank STARTING OUT WITH Python ® Second Edition Tony Gaddis Haywood Community College Addison-Wesley Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City São Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Editor-in-Chief: Editorial Assistant: Vice President, Marketing: Marketing Manager: Marketing Coordinator: Vice President, Production: Managing Editor: Production Project Manager: Manufacturing Buyer: Art Director: Cover Designer: Cover Image: Media Editor: Project Management: Composition and Illustration: Printer/Binder: Cover Printer: Marcia Horton Michael Hirsch Stephanie Sellinger Patrice Jones Yezan Alayan Kathryn Ferranti Vince O’Brien Jeff Holcomb Kayla Smith-Tarbox Lisa McDowell Linda Knowles Joyce Cosentino Wells/JWells Design © Digital Vision Dan Sandin/Wanda Rockwell Sherill Redd, Aptara®, Inc. Aptara®, Inc. Edwards Brothers LeHigh-Phoenix Color/Hagerstown Credits and acknowledgments borrowed from other sources and reproduced, with permission, appear on the Credits page in the endmatter of this textbook. Copyright © 2012, 2009 Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured in the United States of America. This publication...

Words: 76897 - Pages: 308

Free Essay

Python Programming

...Introduction to Programming with Python 1 Outline Introduction to Python Operators & Expressions Data Types & Type Conversion Variables: Names for data Functions Program Flow (Branching) Input from the user Iteration (Looping) 2 What is Python  Python is both an interpreted, general purpose, open source, cross-platform, high level programming language.  Python uses an interpreter. This is a software program that convert Python code to machine language.  It is easy to jump in and experiment with Python in an interactive fashion. Compiling and interpreting  Many languages require you to compile (translate) your program into a form that the machine understands. compile source code Hello.java  execute byte code Hello.class output Python is instead directly interpreted into machine instructions. interpret source code Hello.py output 4 Programming basics     code or source code: instructions in a program. The sequence of syntax: The set of legal structures and commands that can be used in a particular programming language. output: The messages printed to the user by a program. console: The text box onto which output is printed. 5 The Basic Pattern Most of our programs will use the basic pattern of:  Get some user input  Perform some algorithm on the input  Provide results as output Identifiers in Python    ...

Words: 3768 - Pages: 16

Free Essay

Linux Vsc

...Introduction 2 The Python Programming Language 2 History of Python 2 Features 4 Advantages and Disadvantages 5 Python vs. C 5 Summary 11 Bibliography 12 Introduction After comparing several programming languages, I have found many books and websites expressing how fast and efficient Python is. Further, many research papers describe the advantages of adding Python to computer sciences classes. For this reason I decided to study this language and compare it to one that I am familiar with, like the C language. This paper contains the history of Python, from its creation until now. It shows the features that make Python so popular, and the differences between Python and other languages. Most importantly, it explains the four pillars that are the foundation of the Python programming language, which are to provide quality, increase productivity, portability, and integration. Through this paper illustrate the advantages and disadvantages of Python, by showing that, although an interpretative language such as Python will never be as fast as a compiled language like C, it will be more efficient and useful in a variety of cases. The Python Programming Language History of Python Python (Software, 2011) is a relatively recent, object-oriented, interpreted scripting language created by Guido van Rossum at Stichting Mathematisch Centrum (CVI) in the Netherlands. According to Mark Pilgrim, Python is a successor of the ABC language and C (Pilgrim...

Words: 1762 - Pages: 8

Premium Essay

Werefvd

...Python for Informatics Exploring Information Version 0.0.8-d2 Charles Severance Copyright © 2009-2013 Charles Severance. Printing history: October 2013: Major revision to Chapters 13 and 14 to switch to JSON and use OAuth. Added new chapter on Visualization. September 2013: Published book on Amazon CreateSpace January 2010: Published book using the University of Michigan Espresso Book machine. December 2009: Major revision to chapters 2-10 from Think Python: How to Think Like a Computer Scientist and writing chapters 1 and 11-15 to produce Python for Informatics: Exploring Information June 2008: Major revision, changed title to Think Python: How to Think Like a Computer Scientist. August 2007: Major revision, changed title to How to Think Like a (Python) Programmer. April 2002: First edition of How to Think Like a Computer Scientist. This work is licensed under a Creative Common Attribution-NonCommercial-ShareAlike 3.0 Unported License. This license is available at creativecommons.org/licenses/ by-nc-sa/3.0/. You can see what the author considers commercial and non-commercial uses of this material as well as license exemptions in the Appendix titled Copyright Detail. A The LTEX source for the Think Python: How to Think Like a Computer Scientist version of this book is available from http://www.thinkpython.com. Preface Python for Informatics: Remixing an Open Book It is quite natural for academics who are continuously told to “publish or perish” ...

Words: 68401 - Pages: 274

Free Essay

Stuff1

...with Programming Logic and Design, 3rd Edition By Tony Gaddis Python 3 Language Companion for Copyright © 2013 Pearson Education, Inc. Table of Contents Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Introduction 3 Introduction to Python 4 Input, Processing, and Output 10 Modularizing Programs with Functions 21 Decision Structures and Boolean Logic 30 Repetition Structures 39 Value-Returning Functions 48 Input Validation 60 Arrays (Lists) 62 Sorting and Searching 72 Files 77 Menu-Driven Programs 94 Text Processing 96 Recursion 100 Object-Oriented Programming 102 GUI Applications and Event-Driven Programming 111 Appendix A Introduction to IDLE Page 1 Introduction Welcome to the Python Language Companion for Starting Out with Programming Logic and Design, 2nd Edition, by Tony Gaddis. You can use this guide as a reference for the Python Programming Language as you work through the textbook. Each chapter in this guide corresponds to the same numbered chapter in the textbook. As you work through a chapter in the textbook, you can refer to the corresponding chapter in this guide to see how the chapter's topics are implemented in Python. In this book you will also find Python versions of many of the pseudocode programs that are presented in the textbook. Page 2 Chapter 1 Installing Python Introduction to Python Before you can run Python programs...

Words: 31767 - Pages: 128

Premium Essay

Boolean

...Lab 7: Functions This lab accompanies Chapter 6 of Starting Out with Programming Logic & Design. Name: ___________________________ Lab 7.1 – Functions and Pseudocode Critical Review You have been coding with modules in pseudocode and functions when using Python. You modules in pseudocode can be made into functions by returning a value. A function is a special type of module that returns a value back to the part of the program that called it. Most programming languages provide a library of prewritten functions that perform commonly needed tasks. Library functions are built into the programming language and you can call them as needed. They are commonly performed tasks. Help Video: View the tutorial video titled, "lab7-1.wmv" to assist you in completing this lab assignment. Writing Your Own Function that Returns an Integer Step 1: A function contains three parts: a header, a body, and a return statement. The first is a function header which specifies the data type of the value that is to be returned, the name of the function, and any parameter variables used by the function to accept arguments. The body is comprised of one or more statements that are executed when the function is called. In the following space, complete the following: (Reference: Writing Your Own Functions, page 225). a. Write a function with the header named addTen. b. The function will accept an Integer variable named number. c. The function body will...

Words: 2530 - Pages: 11

Free Essay

Student

...CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION This page intentionally left blank CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION R OB E RT W. S EB ES TA University of Colorado at Colorado Springs Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Marcia Horton Editor in Chief: Michael Hirsch Executive Editor: Matt Goldstein Editorial Assistant: Chelsea Kharakozova Vice President Marketing: Patrice Jones Marketing Manager: Yez Alayan Marketing Coordinator: Kathryn Ferranti Marketing Assistant: Emma Snider Vice President and Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Senior Production Project Manager: Marilyn Lloyd Manufacturing Manager: Nick Sklitsis Operations Specialist: Lisa McDowell Cover Designer: Anthony Gemmellaro Text Designer: Gillian Hall Cover Image: Mountain near Pisac, Peru; Photo by author Media Editor: Dan Sandin Full-Service Vendor: Laserwords Project Management: Gillian Hall Printer/Binder: Courier Westford Cover Printer: Lehigh-Phoenix Color This book was composed in InDesign. Basal font is Janson Text. Display font is ITC Franklin Gothic. Copyright © 2012, 2010, 2008, 2006, 2004 by Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured...

Words: 142312 - Pages: 570

Free Essay

Concepts of Programming Languages

...CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION This page intentionally left blank CONCEPTS OF PROGRAMMING LANGUAGES TENTH EDITION R O B E RT W. S EB ES TA University of Colorado at Colorado Springs Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Vice President and Editorial Director, ECS: Marcia Horton Editor in Chief: Michael Hirsch Executive Editor: Matt Goldstein Editorial Assistant: Chelsea Kharakozova Vice President Marketing: Patrice Jones Marketing Manager: Yez Alayan Marketing Coordinator: Kathryn Ferranti Marketing Assistant: Emma Snider Vice President and Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Senior Production Project Manager: Marilyn Lloyd Manufacturing Manager: Nick Sklitsis Operations Specialist: Lisa McDowell Cover Designer: Anthony Gemmellaro Text Designer: Gillian Hall Cover Image: Mountain near Pisac, Peru; Photo by author Media Editor: Dan Sandin Full-Service Vendor: Laserwords Project Management: Gillian Hall Printer/Binder: Courier Westford Cover Printer: Lehigh-Phoenix Color This book was composed in InDesign. Basal font is Janson Text. Display font is ITC Franklin Gothic. Copyright © 2012, 2010, 2008, 2006, 2004 by Pearson Education, Inc., publishing as Addison-Wesley. All rights reserved. Manufactured in the United States...

Words: 142253 - Pages: 570

Premium Essay

Organization of Programing Languages

...or CMP 401 ASSIGNMENT | ORGANIZATION OF PROGRAMMING LANGUAGES | | ANZOTSA JOHN ALAKU | BHU/12/04/05/0042 COMPUTER SCIENCE 400 LEVEL | | | ABRSTRACT My objective for these research was to find out about different programming languages and paradigm in which they belong, the most important use in this research are text and journal by other researchers. After all studies where carried out, I came to a conclusion that one programing language can belong to more than one paradigm C++ C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. Some people say that C++ is a middle language because it has the features of high level and low-level language. As one of the most popular programming languages in the world, C++ is widely used in the software industry. C++ is also used for hardware design to analyze structure. Some of its application domains include systems software, application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games. AspectJ AspectJ is a general-purpose Aspect-Oriented extension to java programming language. It was created at Palo Alto Research Center Incorporated (PARC), now it is an open source project and part of the Eclipse Foundation. AspectJ has everything that Java has and more which...

Words: 3773 - Pages: 16

Premium Essay

Programming Languages

...Unit 1 Research Assignment 1: Exploring Programming Languages Computers don't do anything without someone telling them what to do, much like the average teenager. To make the computer do something useful, you must give it instructions in either of the following two ways: * Write a program that tells a computer what to do, step by step, much as you write out a recipe. * Buy a program that someone else has already written that tells the computer what to do. Ultimately, to get a computer to do something useful, you (or somebody else) must write a program. A program does nothing more than tell the computer how to accept some type of input, manipulate that input, and spit it back out again in some form that humans find useful. Table 1 lists some common types of programs, the types of input that they accept, and the output that they produce. Essentially, a program tells the computer how to solve a specific problem. Because the world is full of problems, the number and variety of programs that people can write for computers is practically endless. But to tell a computer how to solve one big problem, you usually must tell the computer how to solve a bunch of little problems that make up the bigger problem. If you want to make your own video game, for example, you need to solve some of the following problems: * Determine how far to move a cartoon figure (such as a car, a spaceship, or a man) on-screen as the user moves a joystick. * Detect whether the cartoon figure...

Words: 3836 - Pages: 16

Premium Essay

Programing Chapter 1

...variable is a named memory location whose value can vary. An infinite loop is a flow of program logic that repeats and never ends. Software can be classified into two broad types System software and application software. Command line, a location on your computer screen at which you type text entries to communicate with the computer's operating system. The major difference between the two main programming styles in use today is programmer's focus during the earliest planning stages of a project. Graphical user interface(GUI) allows users to interact with a program in a graphical environment. The process of walking through a program's logic on paper before you actually write the program is called desk-checking.  Processing data items may involve organizing or sorting them,checking them for accuracy, or performing calculations with them. Every programming language has rules governing its word usage and punctuation. Using Pseudocode involves writing down all the steps you will use in a program. Before a programmer plans the logic of the program, he or she must understand the problem. F Software can be classified into two broad types: application software and programming software.  T Every programming language has rules governing its word usage and punctuation.  T Besides the popular, comprehensive programming languages such as Java and C++, many programmers use scripting languages such as Python, Lua, Perl, and PHP.  F Professional computer programmers...

Words: 1631 - Pages: 7

Free Essay

Android

...define a compiler-compiler or compiler generator as a tool which creates a parser, interpreter, or compiler from some form of formal description of a language and machine. The earliest and still most common form of compiler-compiler is a parser generator, whose input is a grammar (usually in BNF) of a programming language, and whose generated output is the source code of a parser often used as a component of a compiler. Similarly, code generator-generators (such as J Burg) exist, but such tools have not yet reached maturity. The ideal compiler-compiler takes a description of a programming language and a target instruction set architecture, and automatically generates a usable compiler from them. In practice, the state of the art has yet to reach this degree of sophistication and most compiler generators are not capable of handling semantic or target architecture information. History The first compiler-compiler to use that name was written by Tony Brooker in 1960 and was used to create compilers for the Atlas computer at the University of Manchester, including the Atlas Auto code compiler. However it was rather different from modern compiler-compilers, and today would probably be described as being somewhere between a highly customizable generic compiler and an extensible-syntax language. The name 'compiler-compiler' was far more appropriate for Brooker's system than it is for most modern compiler-compilers, which are more accurately...

Words: 2951 - Pages: 12

Premium Essay

Python Network Programming Cookbook

...www.it-ebooks.info Python Network Programming Cookbook Over 70 detailed recipes to develop practical solutions for a wide range of real-world network programming tasks Dr. M. O. Faruque Sarker BIRMINGHAM - MUMBAI www.it-ebooks.info Python Network Programming Cookbook Copyright © 2014 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: March 2014 Production Reference: 1190314 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84951-346-3 www.packtpub.com Cover Image by Gabrielay La Pintura (linaza100@hotmail...

Words: 36383 - Pages: 146

Free Essay

Advantages of Phase Modulation

...Python Reference Manual Release 2.3.3 Guido van Rossum Fred L. Drake, Jr., editor December 19, 2003 PythonLabs Email: docs@python.org Copyright c 2001, 2002, 2003 Python Software Foundation. All rights reserved. Copyright c 2000 BeOpen.com. All rights reserved. Copyright c 1995-2000 Corporation for National Research Initiatives. All rights reserved. Copyright c 1991-1995 Stichting Mathematisch Centrum. All rights reserved. See the end of this document for complete license and permissions information. Abstract Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for rapid application development, as well as for use as a scripting or glue language to connect existing components together. Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed. This reference manual describes the syntax and “core semantics” of the language. It is terse, but attempts to be exact and complete. The semantics of non-essential built-in object types and of the built-in functions and modules are described in the Python...

Words: 14272 - Pages: 58