Programming for Engineers in Python. Recitation 2
|
|
- Meryl Willis
- 5 years ago
- Views:
Transcription
1 Programming for Engineers in Python Recitation 2
2 Plan Range For loop While loop Lists Modules
3 Operations Arithmetic Operations: + plus - minus * multiply / divide (int / float) % modulo (remainder) ** power Comparison Operators (Return True or False): == equal!= not equal > greater than < less than >= greater than or equal to <= less than or equal to
4 Range Creates an ordered collection of all integers in a given range. range(a, b) contains all integers k satisfying a k < b. range(b) is a shorthand for range(0, b). >>> range(0,10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(-2,2) [-2, -1, 0, 1] >>> range(4,2) [] >>> type(range(3)) <type 'list > # coming soon
5 Range Cont. range(a,b,d), returns the list: a, a+d, a+2d,, a+id until b is reached. >>> range(0,10,2) [0, 2, 4, 6, 8] >>> range(10,0,-2) [10, 8, 6, 4, 2] >>> range(0, 10, -1) [] >>> range(0,10,0) Traceback (most recent call last): File "<pyshell#21>", line 1, in <module> range(0,10,0) ValueError: range() step argument must not be zero
6 For Loop for elem in list (TBD): statement1 statement2 Compute : partialsum = 0 for i in range(1,101): partialsum = partialsum + i print partialsum 5050 Cheat : sum(range(1,101)) determines the scope of the iteration.
7 For Loop Cont. Iterate over strings: name = Assaf for letter in name.upper(): print 'Give me', letter print 'What did we get?', name Give me A Give me S Give me S Give me A Give me F What did we get? Assaf
8 While Loop # Find the smallest divisor n = 9 div=2 while n % div!= 0: div = div+1 print "Smallest divisor of,n,"is",div is the while loop above infinite?
9 While Loop Cont. # Find prime if n < 2: print Out of range" If div!= n: print div," is a divisor of,n else: print n," is prime"
10 While Loop while [expression]: statement1 statement2 true expr statement(s) false Infinite loop: i = 1 while i < 4: print i
11 For / While Equivalence # Find smallest divisor using For: for div in range(2, n+1): if n % div == 0: break print div
12 Break - Aborting Iteration break terminates the nearest enclosing loop, skipping the code that follows the break inside the loop. Useful for getting out of loops when some predefined condition occurs. >>> for i in range(1,10): print(i) if i % 3 == 0: break 1 2 3
13 Lists A list is an ordered sequence of elements. The simplest way to create a list in Python: Enclose its elements in square brackets. >>> my_list = [2,3,5,7,11] >>> my_list [2,3,5,7,11]
14 Lists are Indexable Remember this? H e l l o The same indexing + slicing works for lists!
15 Slicing >>> my_list = [1,2,3,4,5,6,7,8,9,10] >>> my_list[1:5] # slicing ] 2,3,4,5[ >>> my_list[0:-1:2] # slicing an arithmetic progression ] 1,3,5,7,9[ >>> my_list[::2] # shorthand for previous slicing ] 1,3,5,7,9[
16 Slicing Cont. >>> my_list[::-1] # going backwards ] 10,9,8,7,6,5,4,3,2,1[ >>> my_list[3:8:-2] [ ] # output is an empty list. This is NOT an error >>> my_list [1,2,3,4,5,6,7,8,9,10] # slicing does NOT change original list
17 Lists are Indexable Cont >>> my_list = [2, 3, 5, 7, 11] >>> my_list[0] 2 >>> my_list[4] 11 >>> my_list[5] Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> my list[5] IndexError: list index out of range >>> my_list[2:4] [5, 7]
18 Lists Cont. Iterate: >>> sum_list = 0 >>> for k in my_list: sum_list += k # shortcut for sum_list = sum_list + k >>> sum_list 28 Create lists: range( ) creates a list >>> new_list = [i**2 for i in my_list] >>> new_list [4, 9, 25, 49, 121]
19 Length of Lists len returns the length (number of elements) of a list. >>> len(my_list) 5 >>> len([]) 0 Quite often, the length is a useful quantity to have.
20 Lists, Strings, and Beyond Lists can contain strings: days = [ Sunday, Monday", "Tuesday, Wednesday, Thursday, Friday, Saturday ] >>> s =.join(days) 'SundayMondayTuesdayWednesdayThursdayFridaySaturday >>> s.lower() 'sundaymondaytuesdaywednesdaythursdayfridaysaturday >>> s.find('y') 5 >>> first = s[:s.find('y')+1] # what does first contain? >>> first = first[::-1] # and now?
21 Nested Lists >>> mat = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] >>> mat[1] [4, 5, 6] >>> for row in mat: # swap rows and columns for col in row: print col, #, - continue the same line print What is len(mat)?
22 Lists Dynamic Mixing types: assume you want to maintain a list of the students in this course either by name or by id: students = ] Itay, , Alon, Zohar, ] print students[2] >>> Alon Michal decided to join the course, so we update the list: # append - add an element to the end of the list >>> students.append('michal') >>> students ['Itay', , 'Alon', 'Zohar', , 'Michal']
23 Lists Dynamic But Alon wants lo leave the course: >>> students.remove('alon') >>> students ['Itay', , 'Zohar', , 'Michal'] remove removes only the first occurrence of a value.
24 Functions def function_name(argument1, argument2,...): statement1 statement2 return result1, result2, # optional Calling func: [var1, var2, [ = function_name(val1, val2,...) A function is: A named code scope Can receive input parameters Can return output parameters
25 Palindromes Palindromes are read identically from right and left. Examples: ילד בדלי A Man, A Plan, A Canal, Panama Never odd or even ו נ ש ר נ ת ב ע ש ב ד ב ר ע ב ת פ ר ש נ ף ש ר נ ו Pseudo-code: Translate from definition to code - For every index in the string: - Check if word[i] == word[len i 1] # why -1? - False: this is not a palindrome - If all indices survived this is a palindrome
26 Palindromes Code def is_palindrome(word): middle = len(word)/2 for i in range(middle): if word[i]!= word[-i-1]: # no palindrome return False return True # matches all the way Is there a shorter code for identifying palindromes?
27 Functions Scope Consider the following function, operating on two arguments: def linear_combination(x,y): y=2*y return (x+y) The formal parameters x and y are local, and their life time" is just the execution of the function. They disappear when the function is returned. 3, 4 linear_combination 11 x, y
28 Functions Scope >>> a=3 >>> b=4 >>> linear combination(a,b) 11 # this is the correct value >>> a 3 >>> b 4 # b has NOT changed The change in y is local - inside the body of the function.
29 Functions Scope >>> x=3 >>> y=4 >>> linear_combination(x,y) 11 # this is the correct value >>> x 3 >>> y 4 The y in the calling environment and the y in the function are not the same variable!
30 Exercise Unit Testing Test (1) Run my code with some input (2) Check the output My Code
31 Exercise Unit Testing Use the given implementation: - Download hw1.py - Fill in the necessary code instead of the remarks # +++your code here+++ - Instead of printing the code to the shell, return it to the testing function. - Run Module Example s output: OK got: 'Number of donuts: 4' expected: 'Number of donuts: 4' OK got: 'Number of donuts: 9' expected: 'Number of donuts: 9' OK got: 'Number of donuts: many' expected: 'Number of donuts: many' OK got: 'Number of donuts: many' expected: 'Number of donuts: many'
32 Python Code Hierarchy Statement function Module Package
33 Modules All modules and their contents (functions, constants) can be found at >>> import math # mathematical functions >>> dir(math) [' doc ', ' name ', ' package ', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc'] >>> math.pi # a constant >>> math.sqrt(16) # a function 4.0 >>> math.log(8, 2) 3.0
34 Modules Cont. >>> import os #operating system interfaces >>> os.rename( my_file.txt, your_file.txt ) >>> os.mkdir( new_dir ) >>> for root, dirs, files in os.walk('lib/ '): print root, "consumes", print sum(getsize(join(root, name)) for name in files), print "bytes in", len(files), "non-directory files" >>> os.times()[0] # user time
Programming for Engineers in Python. Recitation 3
Programming for Engineers in Python Recitation 3 Plan Modules / Packages Tuples Mutable / Imutable Dictionaries Functions: Scope Call by Ref / Call by Val Frequency Counter Python Code Hierarchy Statement
More informationBuilt-in Types of Data
Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),
More informationProgramming for Engineers in Python. Recitation 3 Functions
Programming for Engineers in Python Recitation 3 Functions Plan Short review FOR and Lists Python references Mutable vs. immutable data types List references Functions Scope Call by assignment Global variables
More informationLab 7: Reading Files, Importing, Bigram Function. Ling 1330/2330: Computational Linguistics Na-Rae Han
Lab 7: Reading Files, Importing, Bigram Function Ling 1330/2330: Computational Linguistics Na-Rae Han Objectives Importing Reading text files range() Bigram function More sorting with sorted() sorted()
More informationProgramming for Engineers in Python
Programming for Engineers in Python Autumn 2016/17 Lecture 2: Lists & Loops 1 Admin Python installation status? 2 Last Week Highlights Memory and variables Different variables types (number, string, bool)
More informationChap 6 Function Define a function, which can reuse a piece of code, just with a few different values.
Chap 6 Function Define a function, which can reuse a piece of code, just with a few different values. def tax(bill): """Adds 8% tax to a restaurant bill.""" bill *= 1.08 print "With tax: %f" % bill return
More information(IUCAA, Pune) kaustubh[at]iucaa[dot]ernet[dot]in.
Basics of Python by Kaustubh Vaghmare (IUCAA, Pune) E-mail: kaustubh[at]iucaa[dot]ernet[dot]in 1 of 29 Thursday 13 February 2014 11:59 AM Topics to be Covered (Not in any specific order.) Basic I/O in
More informationDM550/DM857 Introduction to Programming. Peter Schneider-Kamp
DM550/DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ Operator Precedence expressions are evaluated left-to-right
More information(IUCAA, Pune) kaustubh[at]iucaa[dot]ernet[dot]in 1 of 29 Thursday 16 October :50 PM
Basics of Python by Kaustubh Vaghmare (IUCAA, Pune) E-mail: kaustubh[at]iucaa[dot]ernet[dot]in 1 of 29 Thursday 16 October 2014 03:50 PM Topics to be Covered (Not in any specific order.) Basic I/O in Python
More informationPython. Olmo Zavala R. Python Exercises. Center of Atmospheric Sciences, UNAM. August 24, 2016
Exercises Center of Atmospheric Sciences, UNAM August 24, 2016 NAND Make function that computes the NAND. It should receive two booleans and return one more boolean. logical operators A and B, A or B,
More informationDM536 / DM550 Part 1 Introduction to Programming. Peter Schneider-Kamp.
DM536 / DM550 Part 1 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm536/! CALLING FUNCTIONS 2 Calling Functions so far we have seen three different
More informationHigh Level Scripting. Gino Tosti University & INFN Perugia. 06/09/2010 SciNeGhe Data Analysis Tutorial
High Level Scripting Part I Gino Tosti University & INFN Perugia What is a script? Scripting Languages It is a small program able to automate a repetitive and boring job; It is a list of commands that
More informationStandard Library. Built-in Functions
2 The Standard Library Lab Objective: Python is designed to make it easy to implement complex tasks with little code. To that end, every Python distribution includes several built-in functions for accomplishing
More informationStatistical Data Analysis: Python Tutorial
1 October 4, 2017 Statistical Data Analysis: Python Tutorial Dr A. J. Bevan, Contents 1 Getting started 1 2 Basic calculations 2 3 More advanced calculations 4 4 Data sets 5 4.1 CSV file input.............................................
More informationModule 01: Introduction to Programming in Python
Module 01: Introduction to Programming in Python Topics: Course Introduction Introduction to Python basics Readings: ThinkP 1,2,3 1 Finding course information https://www.student.cs.uwaterloo.ca/~cs116/
More informationArithmetic and Logic Blocks
Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation
More informationProgramming for Engineers in Python. Autumn
Programming for Engineers in Python Autumn 2011-12 Plan Administration: Course site Homework submission guidelines Working environment Python: Variables Editor vs. shell Homework 0 Python Cont. Conditional
More informationSECOND EDITION SAMPLE CHAPTER. First edition by Daryl K. Harms Kenneth M. McDonald. Naomi R. Ceder MANNING
SECOND EDITION SECOND EDITION Covers Python 3 SAMPLE CHAPTER First edition by Daryl K. Harms Kenneth M. McDonald Naomi R. Ceder MANNING The Quick Python Book Second Edition by Naomi R. Ceder Chapter 4
More informationProgramming for Engineers in Python. Recitation 1
Programming for Engineers in Python Recitation 1 Plan Administration: Course site Homework submission guidelines Working environment Python: Variables Editor vs. shell Homework 0 Python Cont. Conditional
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 informationScript started on Thu 25 Aug :00:40 PM CDT
Script started on Thu 25 Aug 2016 02:00:40 PM CDT < M A T L A B (R) > Copyright 1984-2014 The MathWorks, Inc. R2014a (8.3.0.532) 64-bit (glnxa64) February 11, 2014 To get started, type one of these: helpwin,
More informationPython Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]
Python Lists: Lists are Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). All the items belonging to a list can be of different data type.
More informationProgramming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester
Programming Language Control Structures: Selection (switch) Eng. Anis Nazer First Semester 2018-2019 Multiple selection choose one of two things if/else choose one from many things multiple selection using
More informationMentor Graphics Predefined Packages
Mentor Graphics Predefined Packages Mentor Graphics has created packages that define various types and subprograms that make it possible to write and simulate a VHDL model within the Mentor Graphics environment.
More informationData Parallel Execution Model
CS/EE 217 GPU Architecture and Parallel Programming Lecture 3: Kernel-Based Data Parallel Execution Model David Kirk/NVIDIA and Wen-mei Hwu, 2007-2013 Objective To understand the organization and scheduling
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 informationCSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial
CSI31 Lecture 5 Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial 1 3.1 Numberic Data Types When computers were first developed, they were seen primarily as
More informationDSC 201: Data Analysis & Visualization
DSC 201: Data Analysis & Visualization Arrays and Series Dr. David Koop Exception Example def divide(mylist, x,y): newlist = [] try: z = x // y below, mid, above = \ mylist[:z], mylist[z], mylist[z+1:]
More informationComputational Physics
Computational Physics Python Programming Basics Prof. Paul Eugenio Department of Physics Florida State University Jan 17, 2019 http://hadron.physics.fsu.edu/~eugenio/comphy/ Announcements Exercise 0 due
More informationFunctions. Systems Programming Concepts
Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value
More informationFunction Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design
What is a Function? C Programming Lecture 8-1 : Function (Basic) A small program(subroutine) that performs a particular task Input : parameter / argument Perform what? : function body Output t : return
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 informationComputer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries
Computer Programming 5th Week loops (do-while, for), Arrays, array operations, C libraries Hazırlayan Asst. Prof. Dr. Tansu Filik Computer Programming Previously on Bil 200 Low-Level I/O getchar, putchar,
More informationChapter 2. Python Programming for Physicists. Soon-Hyung Yook. March 31, Soon-Hyung Yook Chapter 2 March 31, / 52
Chapter 2 Python Programming for Physicists Soon-Hyung Yook March 31, 2017 Soon-Hyung Yook Chapter 2 March 31, 2017 1 / 52 Table of Contents I 1 Getting Started 2 Basic Programming Variables and Assignments
More informationLAB 1 General MATLAB Information 1
LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by
More informationIntroduction to Scientific and Engineering Computing, BIL108E. Karaman
USING MATLAB INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 To start from Windows, Double click the Matlab icon. To start from UNIX, Dr. S. Gökhan type matlab at the shell prompt.
More informationEssentials for Scientific Computing: Introduction to Python Day 11 & 12
Essentials for Scientific Computing: Introduction to Python Day 11 & 12 Ershaad Ahamed TUE-CMS, JNCASR May 2012 1 Conditionals 1.1 if Construct In python blocks of code are created by indentation. That
More informationLAB 7 FUNCTION PART 2
LAB 7 FUNCTION PART 2 School of Computer and Communication Engineering Universiti Malaysia Perlis 1 OBJECTIVES 1. To differentiate the file scope and block scope. 2. To write recursive function. 3. To
More informationMTH 337 Introduction to Scientific and Mathematical Computing. Fall Instructor: Adam Cunningham University at Buffalo Department of Mathematics
MTH 337 Introduction to Scientific and Mathematical Computing Fall 2015 Instructor: Adam Cunningham University at Buffalo Department of Mathematics Contents 1 Getting Started 4 1.1 Course Description.....................................
More informationA. Matrix-wise and element-wise operations
USC GSBME MATLAB CLASS Reviewing previous session Second session A. Matrix-wise and element-wise operations A.1. Matrix-wise operations So far we learned how to define variables and how to extract data
More informationVariable and Data Type 2
The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 3 Variable and Data Type 2 Eng. Ibraheem Lubbad March 2, 2017 Python Lists: Lists
More informationHow to Design Programs Languages
How to Design Programs Languages Version 4.1 August 12, 2008 The languages documented in this manual are provided by DrScheme to be used with the How to Design Programs book. 1 Contents 1 Beginning Student
More informationCUDA Toolkit 5.0 Performance Report. January 2013
CUDA Toolkit 5.0 Performance Report January 2013 CUDA Math Libraries High performance math routines for your applications: cufft Fast Fourier Transforms Library cublas Complete BLAS Library cusparse Sparse
More informationAt full speed with Python
At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3
More informationVariables. location where in memory is the information stored type what sort of information is stored in that memory
Variables Processing, like many programming languages, uses variables to store information Variables are stored in computer memory with certain attributes location where in memory is the information stored
More informationAdmin. How's the project coming? After these slides, read chapter 13 in your book. Quizzes will return
Recursion CS 1 Admin How's the project coming? After these slides, read chapter 13 in your book Yes that is out of order, but we can read it stand alone Quizzes will return Tuesday Nov 29 th see calendar
More information>>> * *(25**0.16) *10*(25**0.16)
#An Interactive Session in the Python Shell. #When you type a statement in the Python Shell, #the statement is executed immediately. If the #the statement is an expression, its value is #displayed. #Lines
More information6.S189 Homework 2. What to turn in. Exercise 3.1 Defining A Function. Exercise 3.2 Math Module.
6.S189 Homework 2 http://web.mit.edu/6.s189/www/materials.html What to turn in Checkoffs 3, 4 and 5 are due by 5 PM on Monday, January 15th. Checkoff 3 is over Exercises 3.1-3.2, Checkoff 4 is over Exercises
More informationBoolean Data-Type. Boolean Data Type (false, true) i.e. 3/6/2018. The type bool is also described as being an integer: bool bflag; bflag = true;
Programming in C++ If Statements If the sun is shining Choice Statements if (the sun is shining) go to the beach; True Beach False Class go to class; End If 2 1 Boolean Data Type (false, ) i.e. bool bflag;
More informationIntroduction to MATLAB
Outlines January 30, 2008 Outlines Part I: Part II: Writing MATLAB Functions Starting MATLAB Exiting MATLAB Getting Help Command Window Workspace Command History Current Directory Selector Real Values
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Winter 2003 February 10, 2003 1 Introduction This document is a quick reference guide to common features of the Scheme language. It is by no means intended to be a complete
More informationComputing Fundamentals
Computing Fundamentals Salvatore Filippone salvatore.filippone@uniroma2.it 2012 2013 (salvatore.filippone@uniroma2.it) Computing Fundamentals 2012 2013 1 / 18 Octave basics Octave/Matlab: f p r i n t f
More informationIt is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
Chapter 14 Functional Programming Programming Languages 2nd edition Tucker and Noonan It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis
More informationCS 102 Lab 3 Fall 2012
Name: The symbol marks programming exercises. Upon completion, always capture a screenshot and include it in your lab report. Email lab report to instructor at the end of the lab. Review of built-in functions
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 informationPython Intro GIS Week 1. Jake K. Carr
GIS 5222 Week 1 Why Python It s simple and easy to learn It s free - open source! It s cross platform IT S expandable!! Why Python: Example Consider having to convert 1,000 shapefiles into feature classes
More informationExtended Introduction to Computer Science CS1001.py. Lecture 4: Functions & Side Effects ; Integer Representations: Unary, Binary, and Other Bases
Extended Introduction to Computer Science CS1001.py Lecture 4: Functions & Side Effects ; Integer Representations: Unary, Binary, and Other Bases Instructors: Daniel Deutch, Amir Rubinstein Teaching Assistants:
More informationMATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed
MATLAB Constants, Variables & Expression Introduction MATLAB can be used as a powerful programming language. It do have IF, WHILE, FOR lops similar to other programming languages. It has its own vocabulary
More informationExercise: The basics - variables and types
Exercise: The basics - variables and types Aim: Introduce python variables and types. Issues covered: Using the python interactive shell In the python interactive shell you don t need print Creating variables
More informationMatlab Workshop I. Niloufer Mackey and Lixin Shen
Matlab Workshop I Niloufer Mackey and Lixin Shen Western Michigan University/ Syracuse University Email: nil.mackey@wmich.edu, lshen03@syr.edu@wmich.edu p.1/13 What is Matlab? Matlab is a commercial Matrix
More informationS III. Case Study: TI Calculator Numerics
Introduction S III. Case Study: TI Calculator Numerics Texas Instruments started a research project in 1965 to design a pocket calculator. The first pocket calculators appeared in the early 1970 from the
More informationMichele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring
Michele Van Dyne Museum 204B mvandyne@mtech.edu http://katie.mtech.edu/classes/csci136 CSCI 136: Fundamentals of Computer Science II, Spring 2016 1 Review of Java Basics Data Types Arrays NEW: multidimensional
More informationLecture 8 Mathematics
CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 8 Mathematics Uttam Thakore University of Illinois at Urbana-Champaign October 14, 2015 Outline Number theory Combinatorics & probability
More informationAlgorithms and Data Structures
Algorithms and Data Structures 4. Łódź 2018 Exercise Harmonic Sum - Type in the program code - Save it as harmonic.py - Run the script using IPython Wikipedia - This program uses the for loop, the range()
More informationIntroduction to GPGPUs and to CUDA programming model: CUDA Libraries
Introduction to GPGPUs and to CUDA programming model: CUDA Libraries www.cineca.it Marzia Rivi m.rivi@cineca.it NVIDIA CUDA Libraries http://developer.nvidia.com/technologies/libraries CUDA Toolkit includes
More informationPyCUDA. Continued...
PyCUDA Continued... gpuarray Vector Types pycuda.gpuarray.vec All CUDA vector types are supported: float3, int3, long4, etc, Available as numpy data types Field names x, y, z, and w as in CUDA Construct
More information6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x
(Function) -1.1 Math Library Function!"#! $%&!'(#) preprocessor directive #include !*+!"#!, Function Description Example sqrt(x) square root of x sqrt(900.0) is 30.0 sqrt(9.0) is 3.0 exp(x) log(x)
More informationLists How lists are like strings
Lists How lists are like strings A Python list is a new type. Lists allow many of the same operations as strings. (See the table in Section 4.6 of the Python Standard Library Reference for operations supported
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries
More informationLab copy. Do not remove! Mathematics 152 Spring 1999 Notes on the course calculator. 1. The calculator VC. The web page
Mathematics 152 Spring 1999 Notes on the course calculator 1. The calculator VC The web page http://gamba.math.ubc.ca/coursedoc/math152/docs/ca.html contains a generic version of the calculator VC and
More informationIntroduction to C Language
Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,
More informationC++, How to Program. Spring 2016 CISC1600 Yanjun Li 1
Chapter 6 Function C++, How to Program Deitel & Deitel Spring 2016 CISC1600 Yanjun Li 1 Function A function is a collection of statements that performs a specific task - a single, well-defined task. Divide
More informationComputer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans
Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and
More informationNumeric Vectors STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley
Numeric Vectors STAT 133 Gaston Sanchez Department of Statistics, UC Berkeley gastonsanchez.com github.com/gastonstat/stat133 Course web: gastonsanchez.com/stat133 Data Types and Structures To make the
More informationCUDA Toolkit 4.0 Performance Report. June, 2011
CUDA Toolkit 4. Performance Report June, 211 CUDA Math Libraries High performance math routines for your applications: cufft Fast Fourier Transforms Library cublas Complete BLAS Library cusparse Sparse
More informationC Functions. 5.2 Program Modules in C
1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking
More informationBasic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces
Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program
More informationStarting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.
What is MATLAB? MATLAB (short for MATrix LABoratory) is a language for technical computing, developed by The Mathworks, Inc. (A matrix is a rectangular array or table of usually numerical values.) MATLAB
More informationSequence types. str and bytes are sequence types Sequence types have several operations defined for them. Sequence Types. Python
Python Sequence Types Sequence types str and bytes are sequence types Sequence types have several operations defined for them Indexing Python Sequence Types Each element in a sequence can be extracted
More informationIntroduction to MATLAB
Outlines September 9, 2004 Outlines Part I: Review of Previous Lecture Part II: Part III: Writing MATLAB Functions Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Part III:
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationCSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.
CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:
More informationA QUICK INTRODUCTION TO MATLAB
A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally
More informationSML A F unctional Functional Language Language Lecture 19
SML A Functional Language Lecture 19 Introduction to SML SML is a functional programming language and acronym for Standard d Meta Language. SML has basic data objects as expressions, functions and list
More informationIntroduction to Programming
Introduction to Programming session 9 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2010 These slides are created using Deitel s slides Sahrif University of Technology Outlines
More informationtag 220 tan[f l] struct { int i; double d; } sa, sb; struct { int i; double d; } s1, s2;
tag 220 T tag The identifier that may optionally follow the keyword struct, union, or enum in a structure, union, or enumerated type definition, respectively. The tag is used later to refer to that particular
More informationDr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)
Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly
More informationA QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started
A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered
More informationProgramming to Python
Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the
More informationMath 2250 MATLAB TUTORIAL Fall 2005
Math 2250 MATLAB TUTORIAL Fall 2005 Math Computer Lab The Mathematics Computer Lab is located in the T. Benny Rushing Mathematics Center (located underneath the plaza connecting JWB and LCB) room 155C.
More informationGeneral MATLAB Information 1
Introduction to MATLAB General MATLAB Information 1 Once you initiate the MATLAB software, you will see the MATLAB logo appear and then the MATLAB prompt >>. The prompt >> indicates that MATLAB is awaiting
More informationThe Red Hat newlib C Math Library
The Red Hat newlib C Math Library libm 1.17.0 December 2008 Steve Chamberlain Roland Pesch Red Hat Support Jeff Johnston Red Hat Support sac@cygnus.com pesch@cygnus.com jjohnstn@redhat.com Copyright c
More informationSAMPLE CHAPTER. Naomi Ceder MANNING. Foreword by Nicholas Tollervey
SAMPLE CHAPTER Naomi Ceder Foreword by Nicholas Tollervey MANNING The Quick Python Book Third Edition by Naomi Ceder Sample Chapter 4 Copyright 2018 Manning Publications brief contents PART 1 STARTING
More informationThe Cygnus C Math Library
The Cygnus C Math Library libm 1.4 December 1995 Steve Chamberlain Roland Pesch Cygnus Support Cygnus Support sac@cygnus.com pesch@cygnus.com Copyright c 1992, 1993 Cygnus Support libm includes software
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 informationObjectives. You will learn how to process data in ABAP
Objectives You will learn how to process data in ABAP Assigning Values Resetting Values to Initial Values Numerical Operations Processing Character Strings Specifying Offset Values for Data Objects Type
More information06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python
CS95003 - Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / 2014 Subjects 1) Beginning with Python 2) Variables 3) Strings 4) Basic arithmetic operators 5) Flow control 6) Comparison
More informationCT 229 Java Syntax Continued
CT 229 Java Syntax Continued 06/10/2006 CT229 Lab Assignments Due Date for current lab assignment : Oct 8 th Before submission make sure that the name of each.java file matches the name given in the assignment
More informationIntroduction to GNU-Octave
Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016
More informationCS177 Python Programming. Recitation 2 - Computing with Numbers
CS177 Python Programming Recitation 2 - Computing with Numbers Outline Data types. Variables Math library. Range Function What is data (in the context of programming)? Values that are stored and manipulated
More information