Control Statements 1. Conditionals 2 Loops 3 4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You.

Slides:



Advertisements
Similar presentations
Python Mini-Course University of Oklahoma Department of Psychology Lesson 26 Classes and Objects 6/16/09 Python Mini-Course: Lesson 26 1.
Advertisements

A Crash Course Python. Python? Isn’t that a snake? Yes, but it is also a...
Introduction to Programming Lesson 1. Objectives Skills/ConceptsMTA Exam Objectives Understanding Computer Programming Understand computer storage and.
Introduction to Computing Using Python Exceptions (Oops! When things go wrong)  Errors and Exceptions  Syntax errors  State (execution) errors.
Lilian Blot TPOP Practical Assignment Optional, but you are strongly encourage to do it, especially if you are new to programming Available on Module.
Structured programming
Introduction to Python
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
Exceptions COMPSCI 105 S Principles of Computer Science.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 13 Files and Exception Handling 1.
CSC1018F: Object Orientation, Exceptions and File Handling Diving into Python Ch. 5&6 Think Like a Comp. Scientist Ch
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
By: Chris Harvey Python Classes. Namespaces A mapping from names to objects Different namespaces have different mappings Namespaces have varying lifetimes.
Introduction to Computing Using Python Straight-line code  In chapter 2, code was “straight-line”; the Python statements in a file (or entered into the.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Functions Chapter 4 Python for Informatics: Exploring Information
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
P YTHON ’ S C LASSES Ian Wynyard. I NTRODUCTION TO C LASSES A class is the scope in which code is executed A class contains objects and functions that.
RUBY by Ryan Chase.
Guide to Programming with Python Chapter Seven Files and Exceptions: The Trivia Challenge Game.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Introduction to Computing Using Python Exceptions (Oops! When things go wrong)  Errors and Exceptions  Syntax errors  State (execution) errors.
The Python Language Petr Přikryl Part IIb Socrates IP, 15th June 2004 TU of Brno, FIT, Czech Republic.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
9. ITERATIONS AND LOOP STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Head First Python: Ch 3. Files and Exceptions: Dealing with Errors Aug 26, 2013 Kyung-Bin Lim.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
Introduction to Programming Lesson 1. Algorithms Algorithm refers to a method for solving problems. Common techniques for representing an algorithms:
EXCEPTIONS. Catching exceptions Whenever a runtime error occurs, it create an exception object. The program stops running at this point and Python prints.
Xi Wang Yang Zhang. 1. Strings 2. Text Files 3. Exceptions 4. Classes  Refer to basics 2.py for the example codes for this section.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Dr. Philip Cannata 1 Python Classes. Dr. Philip Cannata 2 # The following python statement has python variables which are intended to represent the fact.
EasyCode Foundations Vocabulary Terms.
Python Loops and Iteration
C++, OBJECT ORIENTED PROGRAMMING
Python - Functions.
Introduction to Python
CHAPTER FOUR Functions.
Introduction to Python
Python Primer 2: Functions and Control Flow
Topics Introduction to File Input and Output
Validations and Error Handling
Introduction to Python
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
(Oops! When things go wrong)
Introduction to Python: Day Three
Python for Informatics: Exploring Information
Python Syntax Errors and Exceptions
Recursion Taken from notes by Dr. Neil Moore
CISC101 Reminders All assignments are now posted.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
Stream.
Vocabulary Memory Cards--Sample
Introduction to Programming
Introduction to Computer Science
Introduction to Computer Science
Exception Handling COSC 1323.
CSE 231 Lab 2.
Topics Introduction to File Input and Output
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Using Modules.
Dealing with Runtime Errors
Presentation transcript:

Control Statements 1

Conditionals 2

Loops 3

4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You said', line) return line def polite_echo(): while echo1() != 'bye': pass

Initialization of Loop Values 5

6 def recording_echo(): # initialize entry and lst vlst = [] # get the first input entry = echo1() # test entry while entry != 'bye': # use entry lst.append(entry) # change entry entry = echo1() # repeat # return result return lst

Looping Forever 7

Loops with Guard Conditions 8

Iterations Iteration Statements –Iteration statements all begin with the keyword for 9

Exception Handlers def get_gi_ids(filename): with open(filename) as file: return [extract_gi_id(line) for line in file if line[0] == '>'] IOError: [Errno 2] No such file or directory: 'aa2.fasta‘ 10

Python Errors –Tracebacks –Runtime errors 11

Exception Handling Statements 12

Classes 13

GeneBank Function 14

Problems of GeneBank Function Complexity –Using the representation in a program requires understanding its intricacies. Awkward navigation –Accessing specific parts of the representation requires tricky combinations of index expressions and function calls. Exposure to change –Changes to the representation require widespread changes in every program that uses it. 15

Defining Classes Python’s collection types work as follows: 1.The type is called like a function to create new instances. 2.The call to the type can include arguments used to initialize the new instance. 3.Methods are invoked on instances of types instead of accessing their internal representations. 4.Methods defined for different types can have the same name: when a method is called through a value, Python finds the appropriate function by looking in the definition of the value’s type. 5.The way an instance is printed is based on its type. 16

Defining Classes obj.name() obj.species 17

Example 18

Instance Attributes Access methods 19

Instance Attributes Predicate methods 20

Instance Attributes Initialization methodsString methods 21

Instance Attributes Modification methods Action methods 22 Support methods