CSC1018F: Intermediate Python (Tutorial)

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Μαθαίνοντας Python [Κ4] ‘Guess the Number’
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
JavaScript, Third Edition
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
Python Programming Fundamentals
CSC1018F: Object Orientation, Exceptions and File Handling Diving into Python Ch. 5&6 Think Like a Comp. Scientist Ch
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Input, Output, and Processing
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Built-in Data Structures in Python An Introduction.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
Python Basics. 2 Python History Late 1970s: programming language called ABC at the Centrum voor Wiskunde en Informatica in the Netherlands Audience included.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Data Manipulation Variables, Data Types & Math. Aug Variables A variable is a name (identifier) that points to a value. They are useful to store.
Copyright © Curt Hill The Assignment Operator and Statement The Most Common Statement you will use.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
1 Section 3.2b Arithmetic Operators Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Branching statements.
Python unit_4 review Tue/Wed, Dec 1-2
Topics Designing a Program Input, Processing, and Output
Topics Introduction to Functions Defining and Calling a Void Function
Operators and Expressions
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
2.5 Another Java Application: Adding Integers
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Presented By S.Yamuna AP/IT
Chapter 4: Making Decisions.
Arithmetic Operator Operation Example + addition x + y
Few More Math Operators
Arithmetic operations, decisions and looping
Python Primer 2: Functions and Control Flow
And now for something completely different . . .
Introduction to C++ Programming
Lists in Python.
Georgia Institute of Technology
A First Book of ANSI C Fourth Edition
Numbers.
Arithmetic Expressions & Data Conversions
Operator overloading Dr. Bhargavi Goswami
CSC1018F: Intermediate Python
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Topics Designing a Program Input, Processing, and Output
Variables, Data Types & Math
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Python Primer 1: Types and Operators
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
G. Pullaiah College of Engineering and Technology
Topics Designing a Program Input, Processing, and Output
CSC1018F: Object Orientation, Exceptions and File Handling (Tutorial)
Topics Designing a Program Input, Processing, and Output
COMPUTER PROGRAMMING SKILLS
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Class code for pythonroom.com cchsp2cs
Functions John R. Woodward.
Arithmetic Expressions & Data Conversions
© Sangeeta M Chauhan, Gwalior
Data Types and Expressions
Introduction to Python
Presentation transcript:

CSC1018F: Intermediate Python (Tutorial) Diving into Python Ch. 4 Think Like a Comp. Scientist Ch. 1-6

Mini-Test (1) The precedence of Python mathematical operators from highest to lowest is: Parentheses, Addition/Subtraction, Multiplication/Division, Exponentiation Parentheses, Exponentiation, Multiplication/Division, Addition/Subtraction Parentheses, Exponentiation, Addition/Subtraction, Multiplication/Division Always from left to right in the expression The following sequence of Python statements >>> minute = 59 >>> minute / 60.0 will return: 0.983333333333 a syntax error

Mini-Test (2) The python statement: 0 or "" and "weird" will return: True False "" "weird" Which of the following statements does NOT apply to lambda functions? Lambda functions require parentheses around the arguments Lambda functions may take any number of arguments Lambda functions may contain multiple expressions The return keyword is implied

Mini-Test(3) Which of the following statements does apply to the getattr built-in function: gettatr only works on native datatypes getattr(li, "pop") will execute pop on the list li getattr can take an optional third argument which is a default value The value of the arguments passed to getattr must be known at compile time The Python statement x = "CSC" + str(x) + "F" will: Be rejected by the Python interpreter Be accepted by the Python interpreter only if x is an immutable datatype Be accepted by the Python interpreter only if x is an int, float, dictionary, string, list or tuple Always be accepted by the Python interpreter

Mini-Test (4) Given a function defined as follows: def opt(first, second = 0, third = {}): In order to assign 1 to first, 2 to second, and {} to third, you could call opt as: opt(1, 2) opt(second = 2, first = 1) opt(third = {}, 1, 2) opt(1, 2, {})

Tut Q1: Image Thresholding Assume that an image is represented: With greyscale pixel values in the range 0 (black) to 255 (white) As a list of lists of integers Each sublist represents a row of pixels Write functions to perform the following operations: Threshold(image, threshval) - return an image which has all values below threshval converted to 0 and all those equal or above to 255. Threshval should default to 100 Challenge: try and compress the body of the function into a single line

Tut Q2: More Image Manipulation Create image functions to: CheckValidity(image) - return true if every row of an image is of the same length Expand(image) - return an image with double the horizontal resolution of the input image created by adding an equal amount of white pixels to left and right of the image. Assume that the horizontal resolution is an even number.