Dr. Philip Cannata 1 Python Classes. Dr. Philip Cannata 2 # The following python statement has python variables which are intended to represent the fact.

Slides:



Advertisements
Similar presentations
What's New in Python 2.2 LinuxWorld - New York City - January 2002 Guido van Rossum Director of PythonLabs at Zope Corporation
Advertisements

Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Python Mini-Course University of Oklahoma Department of Psychology Day 4 – Lesson 15 Tuples 5/02/09 Python Mini-Course: Day 4 – Lesson 15 1.
Μαθαίνοντας Python [Κ4] ‘Guess the Number’
An Introduction to Python – Part II Dr. Nancy Warter-Perez.
Structured programming
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Lists/Tuples. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Use 14 doubles What about next.
Lists/Tuples. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Use 14 doubles What about next.
Python Control of Flow.
Dr. Philip Cannata 1 fJyswan. Dr. Philip Cannata 2 10 Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) Relation Jython in Java This.
Python Programming Fundamentals
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 9 Iteration: Recursion 5/02/09 Python Mini-Course: Day 3 - Lesson 9 1.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
CS 177 Week 4 Recitation Slides Variables, Files and Functions.
Lesson 6-3 Example Example 2 Find the difference of –2 and –4. Use counters. 1.Write the subtraction expression. –2 – (–4)
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Python break,continue and pass Statements. The break Statement: for letter in 'Python': # First Example if letter == 'h': break print 'Current Letter.
solve x + (-16) = -12 solve x + (-16) = X = 4.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
Count Controlled Loops Look at the little children … Why is the sun’s face features orange …
Python Basics Tom LeFebvre. Sept , 2002Python Basics2 Python Language Very High-Level Language Scripting Language (no compiling) Simple syntax Easy.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
5 While-Statements © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming.
Formatting Output. Line Endings By now, you’ve noticed that the print( ) function will automatically print out a new line after passing all of the arguments.
Python Let’s get started!.
Chapter 61 Example : For … To… Step For index = 0 To n Step s lstValues.Items.Add(index) Next Control variable Start value Stop value Amount to add to.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
ITERATION. Iteration Computers are often used to automate repetitive tasks. Repeating identical or similar tasks without making errors is something that.
The Python Language Petr Přikryl Part IIb Socrates IP, 15th June 2004 TU of Brno, FIT, Czech Republic.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Lecture 14 – lists, for in loops to iterate through the elements of a list COMPSCI 1 1 Principles of Programming.
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Dr. Philip Cannata 1 Python Overview. Dr. Philip Cannata 2 “Bad program” developed during class # The following python statement has python variables.
Python focus – files The open keyword returns a file object Opening a file myFile = open('C:\file.txt', arg) Optional argument The second argument controls.
Control Statements 1. Conditionals 2 Loops 3 4 Simple Loop Examples def echo(): while echo1(): pass def echo1(): line = input('Say something: ') print('You.
Functions CMSC 201 – Lab 5. Overview Objectives for today's lab:  Practice breaking down a program into multiple functions  Practice writing function.
Introduction to Programming
Computer Programming Fundamentals
SAME SIGNS JUST ADD !! ADDITION OF INTEGERS = (-2) = -10
List comprehensions (and other shortcuts) UW CSE 160 Winter 2016.
Basic operators - strings
List comprehensions (and other shortcuts) UW CSE 160 Winter 2017.
Formatting Output.
Introduction to Strings
Lists in Python.
An Introduction to Python
Passing Parameters by value
List comprehensions (and other shortcuts) UW CSE 160 Spring 2018.
What does this do? def revList(L): if len(L) < = 1: return L x = L[0] LR = revList(L[1:]) return LR + x.
Suggested Layout ** Designed to be printed on white A3 paper.
Add or Subtract? x =.
Introduction to Python: Day Two
Writing Functions( ) (Part 4)
Introduction to Strings
functions: argument, return value
Python Basics with Jupyter Notebook
15-110: Principles of Computing
L8-2 Notes: Adding Integers
Text to Text Compare and Contrast
Introduction to Strings
Understanding Code Workshop 2.
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
Programming II Vocabulary Review Loops & functions
COMPUTING.
Python Reserved Words Poster
Tuple.
Presentation transcript:

Dr. Philip Cannata 1 Python Classes

Dr. Philip Cannata 2 # The following python statement has python variables which are intended to represent the fact that each cartoon character has the given amount of money. tom, jerry, phineas, ferb, mickey, donald = 1000, 2000, 3000, 4000, 5000, 6000 print tom, jerry # The following function can be passed three integer arguments, it subtracts the third argument from the first and adds the third argument to the second. It returns the changed values of the first two arguments. def takeMoney(c1, c2, amt) : c1-=amt c2+=amt return c1, c2 # The following are data structures that pair appropriate cartoon characters. # This data structure is a list of lists. duo=[[tom, jerry], [phineas, ferb], [mickey, donald]] # This data structure is a tuple of lists. duo=([tom, jerry], [phineas, ferb], [mickey, donald]) # This data structure is a tuple of tuples. duo=((tom, jerry), (phineas, ferb), (mickey, donald)) # This data structure is a list of tuples. duo=[(tom, jerry), (phineas, ferb), (mickey, donald)] # The following "for loop" iterates over duo calling takeMoney for each pair in duo. cnt=0 for i in duo : if cnt == 0: tom, jerry = takeMoney(i[0], i[1], 50) elif cnt == 1 : phineas, ferb = takeMoney(i[0], i[1], 50) elif cnt == 2 : donald, mickey = takeMoney(i[0], i[1], 50) cnt+=1 print tom, jerry, phineas, ferb, mickey, donald # Returns

Dr. Philip Cannata 3

Dr. Philip Cannata 4