DISCRETE ELEMENT METHOD (DEM) SIMULATION USING OPEN-SOURCE CODES
|
|
- Ginger Jones
- 5 years ago
- Views:
Transcription
1 DISCRETE ELEMENT METHOD (DEM) SIMULATION USING OPEN-SOURCE CODES Using PYTHON Dr Daniel Barreto 1 Lecturer in Geotechnical Engineering d.barreto@napier.ac.uk July 8 th, 2015 D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
2 Lecture Outline 1 PYTHON - YADE s language Python Basics 2 Data types Lists Tuples 3 Control structures 4 Examples of PYTHON functions used in YADE D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
3 Python - Basic calculations Python is an interpretative language. You can use PYTHON to run programs from Terminal (command window). Python is also an interactive language that is capable of evaluating arbitrary commands. This is particularly for validation and verification problems. Many people even use PYTHON as a calculator. For example: PYTHON as calculator user@user:~$ python Python (default, Jun , 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
4 PYTHON - Arithmetic Operators Assuming that a = 10 and b = a+b=30 (Addition) b-a=10 (Subtraction) a*b=200 (Product) b/a=2 (Division) b%a=0 (Module) a**b=10 20 (Power) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
5 Variables - Declaration and printing A typical first program can be created using PYTHON: Hello World! >>> print Hello! D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
6 Variables - Declaration and printing A typical first program can be created using PYTHON: Hello World! >>> print Hello! In PYTHON variables (and constants) do not need to be declared. This is an advantage in contrast to other programming languages (i.e. C++ and FORTRAN). For example: Calculations with variables >>> x=2 >>> y=1 >>> x+y D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
7 Functions - Declaration In PYTHON it is easy to define and declare functions. It is only necessary to write: def functionname(parameters): Hello World! as a function >>> def functionone():... print Hello... D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
8 Functions - Declaration In PYTHON it is easy to define and declare functions. It is only necessary to write: def functionname(parameters): Hello World! as a function >>> def functionone():... print Hello... If the function has several parameters, these are separated by commas. It is not needed to specify the parameter type (also in contrast to other programmming languages). It is very important to maintain the indentation when using PYTHON because functions have no explicit end. There are no brackets or parenthesis as in other languages. The only delimiters used in PYTHON are : and the indentation (i.e. spacing or tabulation). D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
9 Indentation and calling functions Code blocks are defined by indentation. A code block can be a conditional ( if ), loop or cycle ( for, while ), etc. Indentation starts and finishes a block. Character spacing is significant and must always be consistent. Functions in PYTHON as in other languages are called by their name and parameters. In this way, functionone() is called as: Calling a function >>> functionone() At this point is good to verify what happens when you call that function (functionone()) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
10 Indentation and calling functions Code blocks are defined by indentation. A code block can be a conditional ( if ), loop or cycle ( for, while ), etc. Indentation starts and finishes a block. Character spacing is significant and must always be consistent. Functions in PYTHON as in other languages are called by their name and parameters. In this way, functionone() is called as: Calling a function >>> functionone() At this point is good to verify what happens when you call that function (functionone()) A further example: Write a function addition() that returns the sum of two integer numbers x and z. Verify that the function works properly. D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
11 PYTHON - Data Types Numbers Characters Dictionaries Lists [a, b, c] Tuples (a, b, c) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
12 Lists The most versatile data type in PYTHON. A list can contain any variable type and it os declared as: List declaration >>> list1 = [1,2,3] The first element of that list (and any other) is identified with the index 0. For example: D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
13 Lists The most versatile data type in PYTHON. A list can contain any variable type and it os declared as: List declaration >>> list1 = [1,2,3] The first element of that list (and any other) is identified with the index 0. For example: Individual elements of a list >>> list1 = [ DEM,2,3] >>> list1[0] D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
14 Lists The most versatile data type in PYTHON. A list can contain any variable type and it os declared as: List declaration >>> list1 = [1,2,3] The first element of that list (and any other) is identified with the index 0. For example: Individual elements of a list >>> list1 = [ DEM,2,3] >>> list1[0] Example: Create the list Crear la lista li = [ One, 1, 1.2] and then verify the content for each of its elements. D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
15 Lists Additional elements can be added to existing lists... Adding elements to existing lists >>> list1.append( Three ) >>> list[3] Similarly, individual elements can be removed using the command remove. For example: Removing individual elements from a list >>> list1.remove(2) >>> list1[1] D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
16 Tuples Tuples are essentialy and immutable (unchangeable) list. Once a tuple has been created it cannot be changed. Tuples are declared in the same way as lists but using parenthesis () instead of square brackets []. Identification of and access to individual elements of a tuple is made in the same manner as explained for the case of lists. D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
17 Tuples Tuples are essentialy and immutable (unchangeable) list. Once a tuple has been created it cannot be changed. Tuples are declared in the same way as lists but using parenthesis () instead of square brackets []. Identification of and access to individual elements of a tuple is made in the same manner as explained for the case of lists. An example... Working with tuples >>> tuple1=(1,2,3) >>> tuple1[0] >>> tuple1.append(4) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
18 Tuples Tuples are essentialy and immutable (unchangeable) list. Once a tuple has been created it cannot be changed. Tuples are declared in the same way as lists but using parenthesis () instead of square brackets []. Identification of and access to individual elements of a tuple is made in the same manner as explained for the case of lists. An example... Working with tuples >>> tuple1=(1,2,3) >>> tuple1[0] >>> tuple1.append(4) What do you expect to have when executing the code above? D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
19 PYTHON - Comparison operators Assuming that a = 10 and b = a==b False (Equality) a!=b True (Inequality) a>b False (Greater than) a<b True (Lower than) a>=b False (Greater or equal than) a<=b True (Lower or equal than) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
20 PYTHON - Logical operators Assuming that a = 10 and b = a and b True Both arguments must be true for the condition to be true a or b True If any of the argumets is different from zero, the condition is true not(a and b) False If one condition is true, the operator not makes it false D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
21 if A control structure, whether it is a conditional (if) or a loop/cycle (for) has a very simple syntaxis that follows the basic principles for PYTHON The if conditional >>> def if1(x,y):... if x == 1:... print Bien... if x >= 2:... z = x+y... print z Let s verify this works using the following commands: Verifying... >>> if1(1,2) >>> if1(2,1) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
22 for A control structure, whether it is a conditional (if) or a loop/cycle (for) has a very simple syntaxis that follows the basic principles for PYTHON The for loop/cycle >>> def for1():... for x in range(5):... print x D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
23 for A control structure, whether it is a conditional (if) or a loop/cycle (for) has a very simple syntaxis that follows the basic principles for PYTHON The for loop/cycle >>> def for1():... for x in range(5):... print x Example: Create a list with three integer numbers. Then define a function that prints each of these elements and the sum of them. Use a conditional structure that verifues and prints if the sum is greater or lower than 10. D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
24 More PYTHON details Dive Into Python. A Book By Mark Pilgrim. D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
25 Outputting data A function to output macro-scale data to a text file def plotadddata(): plot.adddata( sxx=utils.getstress()[0,0], syy=utils.getstress()[1,1], szz=utils.getstress()[2,2], poros=porosity(), t=o.time ) plot.savedatatxt( macrofile,vars=( t, sxx, syy, szz, poros )) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
26 A more general output function Formatted output... def fabric(): filename= fabric +str(o.iter) f = open(filename, w ) f.write( id1 id2 x_cp y_cp z_cp n_x n_y n_z ) for i in O.interactions: if not i.isreal: continue tacts = i.geom.contactpoint nmls = i.geom.normal f.write( %-16d %-16d %-16g %-16g %-16g %-16g %-16g %-16g\n %(i.id1, i.id2,tacts[0],tacts[1],tacts[2],nmls[0],nmls[1],nmls[2],)) f.close D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
27 Servo-control for a drained triaxial test def servo(): gain=0.001 tol=0.1 sy_req=-250. sz_req=-250. sr_x=-.1 sr_y=0. sr_z=0. sy_curr=utils.getstress()[1,1] sz_curr=utils.getstress()[2,2] sry_curr=o.cell.velgrad[1,1] srz_curr=o.cell.velgrad[2,2] if fabs(sy_curr-sy_req)>=tol: sr_y=sry_curr+gain*(sy_req-sy_curr) else: sr_y=sry_curr if fabs(sz_curr-sz_req)>=tol: sr_z=srz_curr+gain*(sz_req-sz_curr) else: sr_z=srz_curr O.cell.velGrad=Matrix3(sr_x,0,0,0,sr_y,0,0,0,sr_z) D. Barreto (ENU) DEM-ZU-2015 July 8 th, / 19
DISCRETE ELEMENT METHOD (DEM) SIMULATION USING OPEN-SOURCE CODES
DISCRETE ELEMENT METHOD (DEM) SIMULATION USING OPEN-SOURCE CODES Introduction - Linux Dr Daniel Barreto 1 Lecturer in Geotechnical Engineering d.barreto@napier.ac.uk July 8 th, 2015 D. Barreto (ENU) DEM-ZJU-2015
More informationStatements 2. a operator= b a = a operator b
Statements 2 Outline Note: i=i+1 is a valid statement. Don t confuse it with an equation i==i+1 which is always false for normal numbers. The statement i=i+1 is a very common idiom: it just increments
More informationData Types and Variables in C language
Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators
More informationSenthil Kumaran S
Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created
More informationPython as a First Programming Language Justin Stevens Giselle Serate Davidson Academy of Nevada. March 6th, 2016
Python as a First Programming Language Justin Stevens Giselle Serate Davidson Academy of Nevada Under Supervision of: Dr. Richard Kelley Chief Engineer, NAASIC March 6th, 2016 Science Technology Engineering
More informationCOMP1730/COMP6730 Programming for Scientists. Sequence types, part 2
COMP1730/COMP6730 Programming for Scientists Sequence types, part 2 Lecture outline * Lists * Mutable objects & references Sequence data types (recap) * A sequence contains n 0 values (its length), each
More informationC++ for Python Programmers
C++ for Python Programmers Adapted from a document by Rich Enbody & Bill Punch of Michigan State University Purpose of this document This document is a brief introduction to C++ for Python programmers
More informationFunctions, Scope & Arguments. HORT Lecture 12 Instructor: Kranthi Varala
Functions, Scope & Arguments HORT 59000 Lecture 12 Instructor: Kranthi Varala Functions Functions are logical groupings of statements to achieve a task. For example, a function to calculate the average
More informationThere are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:
Numeric Types There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals: 1-123 +456 2. Long integers, of unlimited
More informationCS 234 Python Review Part 2
CS 234 Python Review Part 2 Recap import function: define, return boolean, conditional, branching loop: for, range, while file: open, close, readlines string: split Classes Define blueprint for a custom
More informationChapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.
Chapter 1 Linear Equations and Straight Lines 2 of 71 Outline 1.1 Coordinate Systems and Graphs 1.4 The Slope of a Straight Line 1.3 The Intersection Point of a Pair of Lines 1.2 Linear Inequalities 1.5
More informationCME 193: Introduction to Scientific Python Lecture 4: Strings and File I/O
CME 193: Introduction to Scientific Python Lecture 4: Strings and File I/O Nolan Skochdopole stanford.edu/class/cme193 4: Strings and File I/O 4-1 Contents Strings File I/O Classes Exercises 4: Strings
More informationOUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.
1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN
More informationGetting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013
CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?
More informationLecture no
Advanced Algorithms and Computational Models (module A) Lecture no. 3 29-09-2014 Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 28 Expressions, Operators and Precedence Sequence Operators The following
More information[Software Development] Python (Part A) Davide Balzarotti. Eurecom Sophia Antipolis, France
[Software Development] Python (Part A) Davide Balzarotti Eurecom Sophia Antipolis, France 1 Homework Status 83 registered students 41% completed at least one challenge 5 command line ninjas 0 python masters
More informationLarge-Scale Networks
Large-Scale Networks 3b Python for large-scale networks Dr Vincent Gramoli Senior lecturer School of Information Technologies The University of Sydney Page 1 Introduction Why Python? What to do with Python?
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationVariable and Data Type I
Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store
More informationIntroduction to Python
May 25, 2010 Basic Operators Logicals Types Tuples, Lists, & Dictionaries and or Building Functions Labs From a non-lab computer visit: http://www.csuglab.cornell.edu/userinfo Running your own python setup,
More informationPython An Introduction
Python An Introduction Calle Lejdfors and Lennart Ohlsson calle.lejdfors@cs.lth.se Python An Introduction p. 1 Overview Basic Python Numpy Python An Introduction p. 2 What is Python? Python plays a key
More informationPython memento TI-Smart Grids
Python memento TI-Smart Grids Genoveva Vargas-Solar French Council of Scientific Research, LIG genoveva.vargas@imag.fr http://vargas-solar.com/data-centric-smart-everything/ * This presentation was created
More informationIntroduction to Python, Cplex and Gurobi
Introduction to Python, Cplex and Gurobi Introduction Python is a widely used, high level programming language designed by Guido van Rossum and released on 1991. Two stable releases: Python 2.7 Python
More information61A Lecture 2. Wednesday, September 4, 2013
61A Lecture 2 Wednesday, September 4, 2013 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions:
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationDownloaded from Chapter 2. Functions
Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create
More informationLearning R via Python...or the other way around
Learning R via Python...or the other way around Dept. of Politics - NYU January 7, 2010 What We ll Cover Brief review of Python The Zen of Python How are R and Python the same, and how are they different
More informationThe Practice of Computing Using PYTHON
The Practice of Computing Using PYTHON William Punch Richard Enbody Chapter 6 Lists and Tuples 1 Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Data Structures 2 Data Structures
More informationCS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco
CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level
More informationKey Differences Between Python and Java
Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.
More informationSome material adapted from Upenn cmpe391 slides and other sources
Some material adapted from Upenn cmpe391 slides and other sources History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationPython Review IPRE
Python Review 2 Jay Summet 2005-12-31 IPRE Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing Elements Cloning Slices Mutable Types: Lists Dictionaries
More informationPart I. Wei Tianwen. A Brief Introduction to Python. Part I. Wei Tianwen. Basics. Object Oriented Programming
2017 Table of contents 1 2 Integers and floats Integer int and float float are elementary numeric types in. integer >>> a=1 >>> a 1 >>> type (a) Integers and floats Integer int and float
More informationPython for ArcGIS. Lab 1.
Python for ArcGIS. Lab 1. Python is relatively new language of programming, which first implementation arrived around early nineties of the last century. It is best described as a high level and general
More informationCSE 115. Introduction to Computer Science I
CSE 115 Introduction to Computer Science I Note about posted slides The slides we post will sometimes contain additional slides/content, beyond what was presented in any one lecture. We do this so the
More informationPython: common syntax
Lab 09 Python! Python Intro Main Differences from C++: True and False are capitals Python floors (always down) with int division (matters with negatives): -3 / 2 = -2 No variable data types or variable
More informationPython Programming Exercises 1
Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them
More informationList Comprehensions. Function Definitions. This is the same as mapping the doubling function on the list [1,2,3], but without an explicit
List Comprehensions Python provides an elegant mechanism for building a list by embedding a for within list brackets. This a termed a List Comprehension. The general form is an expression, followed by
More informationProgramming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur
Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,
More informationPython lab session 1
Python lab session 1 Dr Ben Dudson, Department of Physics, University of York 28th January 2011 Python labs Before we can start using Python, first make sure: ˆ You can log into a computer using your username
More informationPython in 10 (50) minutes
Python in 10 (50) minutes https://www.stavros.io/tutorials/python/ Python for Microcontrollers Getting started with MicroPython Donald Norris, McGrawHill (2017) Python is strongly typed (i.e. types are
More informationProgramming with Python
Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2
More informationIntroduction to Python
Introduction to Python Efstratios RAPPOS efstratios.rappos@heig-vd.ch Slide 1 2016 HEIG-VD SNU Summer School Background Easy and popular programming language Interpreted: must have python installed to
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationCrayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361)
Crayon (.cry) Language Reference Manual Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361) 1 Lexical Elements 1.1 Identifiers Identifiers are strings used
More informationProgramming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan
Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with
More informationCOMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.
COMP1730/COMP6730 Programming for Scientists Data: Values, types and expressions. Lecture outline * Data and data types. * Expressions: computing values. * Variables: remembering values. What is data?
More informationpython 01 September 16, 2016
python 01 September 16, 2016 1 Introduction to Python adapted from Steve Phelps lectures - (http://sphelps.net) 2 Python is interpreted Python is an interpreted language (Java and C are not). In [1]: 7
More informationCOMP519 Web Programming Lecture 17: Python (Part 1) Handouts
COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents
More informationIntroduction to Python
Introduction to Python CB2-101 Introduction to Scientific Computing November 11 th, 2014 Emidio Capriotti http://biofold.org/emidio Division of Informatics Department of Pathology Python Python high-level
More informationFunctions Structure and Parameters behind the scenes with diagrams!
Functions Structure and Parameters behind the scenes with diagrams! Congratulations! You're now in week 2, diving deeper into programming and its essential components. In this case, we will talk about
More informationHere n is a variable name. The value of that variable is 176.
UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence
More informationSTA141C: Big Data & High Performance Statistical Computing
STA141C: Big Data & High Performance Statistical Computing Lecture 1: Python programming (1) Cho-Jui Hsieh UC Davis April 4, 2017 Python Python is a scripting language: Non-scripting language (C++. java):
More informationLesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University
Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationLecture 4. while and for loops if else test Tuples Functions. Let us start Python Ssh (putty) to UNIX/Linux computer puccini.che.pitt.
Lecture 4 while and for loops if else test Tuples Functions Let us start Python Ssh (putty) to UNIX/Linux computer puccini.che.pitt.edu Launching Python > python Quick Reminder: while Loop Example >>>
More informationDynamic Data Structures and First-Class Citizens: Python Features That Can Make Data Analysis More Flexible and Powerful
Dynamic Data Structures and First-Class Citizens: Python Features That Can Make Data Analysis More Flexible and Powerful Johnny Wei-Bing Lin University of Washington Bothell and North Park University July
More informationPython. Tutorial Lecture for EE562 Artificial Intelligence for Engineers
Python Tutorial Lecture for EE562 Artificial Intelligence for Engineers 1 Why Python for AI? For many years, we used Lisp, because it handled lists and trees really well, had garbage collection, and didn
More informationIteration. # a and b are now equal # a and b are no longer equal Multiple assignment
Iteration 6.1. Multiple assignment As you may have discovered, it is legal to make more than one assignment to the same variable. A new assignment makes an existing variable refer to a new value (and stop
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationIntroduction to Scientific Computing
Introduction to Scientific Computing Dr Hanno Rein Last updated: October 12, 2018 1 Computers A computer is a machine which can perform a set of calculations. The purpose of this course is to give you
More informationPython: Functions. Thomas Schwarz, SJ Marquette University
Python: Functions Thomas Schwarz, SJ Marquette University History Early computer programming was difficult Not only because interacting with the computer was difficult Data was entered by setting switches,
More informationInteractive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationUniversity of Washington CSE 140 Introduction to Data Programming Winter Midterm exam. February 6, 2013
University of Washington CSE 140 Introduction to Data Programming Winter 2013 Midterm exam February 6, 2013 Name: Solutions UW Net ID (username): This exam is closed book, closed notes. You have 50 minutes
More informationTeaching London Computing
Teaching London Computing A Level Computer Science Topic 3: Advanced Programming in Python William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London Aims Further
More informationCS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013
CS61A Lecture 16 Amir Kamil UC Berkeley February 27, 2013 Announcements HW5 due tonight Trends project due on Tuesday Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission
More informationMEIN 50010: Python Flow Control
: Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-11 Program Overview Program Code Block Statements Expressions Expressions & Statements An expression has
More informationHistory Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability
History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Some material adapted from Upenn cmpe391 slides and other sources Invented in the Netherlands,
More informationInteractive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D
1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.
More informationSpring Semester 13, Dr. Punch. Exam #1 (2/14), form 1 A
Spring Semester 13, Dr. Punch. Exam #1 (2/14), form 1 A Last name (printed): First name (printed): Directions: a) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. b) You have 80 minutes
More informationLecture 2 FORTRAN Basics. Lubna Ahmed
Lecture 2 FORTRAN Basics Lubna Ahmed 1 Fortran basics Data types Constants Variables Identifiers Arithmetic expression Intrinsic functions Input-output 2 Program layout PROGRAM program name IMPLICIT NONE
More informationVariable and Data Type I
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved
More informationA Computational System for Polynomials with Two Variables
CS 610 Data Structures & Algorithms Programming Project A Computational System for Polynomials with Two Variables A polynomial with two variables x and y consists of a summation of terms of the form where
More informationIntroduction to Python
Introduction to Python خانه ریاضیات اصفهان فرزانه کاظمی زمستان 93 1 Why Python? Python is free. Python easy to lean and use. Reduce time and length of coding. Huge standard library Simple (Python code
More informationSTSCI Python Introduction. Class URL
STSCI Python Introduction Class 2 Jim Hare Class URL www.pst.stsci.edu/~hare Each Class Presentation Homework suggestions Example files to download Links to sites by each class and in general I will try
More informationCS61A Lecture 16. Amir Kamil UC Berkeley February 27, 2013
CS61A Lecture 16 Amir Kamil UC Berkeley February 27, 2013 Announcements HW5 due tonight Trends project due on Tuesday Partners are required; find one in lab or on Piazza Will not work in IDLE New bug submission
More informationIntroductory Linux Course. Python I. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University
Introductory Linux Course Martin Dahlö UPPMAX Author: Nina Fischer Dept. for Cell and Molecular Biology, Uppsala University August, 2018 Outline Python basics get started with Python Data types Control
More informationConstraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial
1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the
More informationLists, loops and decisions
Caltech/LEAD Summer 2012 Computer Science Lecture 4: July 11, 2012 Lists, loops and decisions Lists Today Looping with the for statement Making decisions with the if statement Lists A list is a sequence
More informationSketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321
Sketchpad Graphics Language Reference Manual Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321 October 20, 2013 1. Introduction This manual provides reference information for using the SKL (Sketchpad
More informationPython. Jae-Gil Lee Based on the slides by K. Naik, M. Raju, and S. Bhatkar. December 28, Outline
Python Jae-Gil Lee Based on the slides by K. Naik, M. Raju, and S. Bhatkar December 28, 2011 1 Outline Introduction Installation and Use Distinct Features Python Basics Functional Example Comparisons with
More informationPython - Variable Types. John R. Woodward
Python - Variable Types John R. Woodward Variables 1. Variables are nothing but named reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
More informationVersion B Final Exam
CS112 Spring 2013 Dr. Kinga Dobolyi Version B Final Exam Do not open this exam until you are told. Read these instructions: 1. This is a closed book exam. No calculators, notes, or other aids are allowed.
More informationScientific Computing
Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course
More informationCS 112: Intro to Comp Prog
CS 112: Intro to Comp Prog Importing modules Branching Loops Program Planning Arithmetic Program Lab Assignment #2 Upcoming Assignment #1 Solution CODE: # lab1.py # Student Name: John Noname # Assignment:
More informationCMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm
CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm Name: Discussion Time: 10am 11am 12pm 1pm 2pm 3pm TA Name (Circle): Alex Austin Ayman Brian Damien Daniel K. Daniel P. Greg Tammy Tim Vitung Will K. Instructions
More informationlambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
Outline 1 Guessing Secrets functions returning functions oracles and trapdoor functions 2 anonymous functions lambda forms map(), reduce(), filter(), eval(), and apply() estimating π with list comprehensions
More informationComputational Physics - Fortran February 1997
Fortran 90 Decision Structures IF commands 3 main possibilities IF (logical expression) IF (logical expression) THEN IF (logical expression) THEN IF (logical expression) THEN expression TRUE expression
More informationPython Programming, bridging course 2011
Python Programming, bridging course 2011 About the course Few lectures Focus on programming practice Slides on the homepage No course book. Using online resources instead. Online Python resources http://www.python.org/
More informationAt the end of this lecture you should be able to have a basic overview of fundamental structures in C and be ready to go into details.
Objective of this lecture: At the end of this lecture you should be able to have a basic overview of fundamental structures in C and be ready to go into details. Fundamental Programming Structures in C
More informationCS 1301 Exam 2 Fall 2010
CS 1301 Exam 2 Fall 2010 Name : Grading TA: Devices: If your cell phone, pager, PDA, beeper, ipod, or similar item goes off during the exam, you will lose 10 points on this exam. Turn all such devices
More information61A Lecture 2. Friday, August 28, 2015
61A Lecture 2 Friday, August 28, 2015 Names, Assignment, and User-Defined Functions (Demo) Types of Expressions Primitive expressions: 2 add 'hello' Number or Numeral Name String Call expressions: max
More informationTypes, lists & functions
Week 2 Types, lists & functions Data types If you want to write a program that allows the user to input something, you can use the command input: name = input (" What is your name? ") print (" Hello "+
More informationCHIL CSS HTML Integrated Language
CHIL CSS HTML Integrated Language Programming Languages and Translators Fall 2013 Authors: Gil Chen Zion gc2466 Ami Kumar ak3284 Annania Melaku amm2324 Isaac White iaw2105 Professor: Prof. Stephen A. Edwards
More informationLecture #12: Immutable and Mutable Data. Last modified: Mon Feb 22 16:33: CS61A: Lecture #12 1
Lecture #12: Immutable and Mutable Data Last modified: Mon Feb 22 16:33:22 2016 CS61A: Lecture #12 1 Listing Leaves def leaf_labels(tree): """A list of the labels of all leaves in TREE.""" Last modified:
More informationIntroduction to Python
Introduction to Python Jon Kerr Nilsen, Dmytro Karpenko Research Infrastructure Services Group, Department for Research Computing, USIT, UiO Why Python Clean and easy-to-understand syntax alldata = cpickle.load(open(filename1,
More informationBasic Python Revision Notes With help from Nitish Mittal
Basic Python Revision Notes With help from Nitish Mittal HELP from Documentation dir(module) help() Important Characters and Sets of Characters tab \t new line \n backslash \\ string " " or ' ' docstring
More informationPython Review IPRE
Python Review Jay Summet 2005-12-31 IPRE Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing Elements Cloning Slices Mutable Types: Lists Dictionaries
More informationAPT Session 2: Python
APT Session 2: Python Laurence Tratt Software Development Team 2017-10-20 1 / 17 http://soft-dev.org/ What to expect from this session: Python 1 What is Python? 2 Basic Python functionality. 2 / 17 http://soft-dev.org/
More informationIntroduction to Python
Introduction to Python EECS 4415 Big Data Systems Tilemachos Pechlivanoglou tipech@eecs.yorku.ca 2 Background Why Python? "Scripting language" Very easy to learn Interactive front-end for C/C++ code Object-oriented
More information