C463 / B551 Artificial Intelligence Dana Vrajitoru Python.

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

Programming Languages and Paradigms The C Programming Language.
What is a scripting language? What is Python?
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Python (yay!) November 16, Unit 7. Recap We can store values in variables using an assignment statement >>>x = We can get input from the user using.
Chapter 8: Introduction to High-level Language Programming Invitation to Computer Science, C++ Version, Third Edition.
Python Crash Course by Monica Sweat. Python Perspective is strongly typed, interpreted language is used to define scripts (Don't even need to define a.
Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.
Introduction to JavaScript for Python Programmers
The Python Programming Language Matt Campbell | Steve Losh.
CSC 9010: Natural Language Processing
Python quick start guide
Python.
Programming 101 with Python: an open-source, cross-platform, and fun language By J. Burton Browning, Ed.D. Copyright © J. Burton Browning All rights reserved.
Python Programming Fundamentals
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
INTERNET APPLICATION DEVELOPMENT For More visit:
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
Computer Science 111 Fundamentals of Programming I Overview of Programming.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
1 Python CIS*2450 Advanced Programming Concepts Material for this lecture was developed by Dr. D. Calvert.
CS1022 Computer Programming & Principles Lecture 1.2 A brief introduction to Python.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Hans-Peter Plag November 6, 2014 Session 4 (Programming Languages) (Data Types and Variables) Expressions and Operators Flow Control.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Python Functions.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
Fundamentals of Programming I Overview of Programming
Topics Introduction to Functions Defining and Calling a Void Function
CS1022 Computer Programming & Principles
Introduction to Python
Topic: Functions – Part 2
Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. It was created by Guido van Rossum during.
Engineering Innovation Center
PH2150 Scientific Computing Skills
Chapter 10 Programming Fundamentals with JavaScript
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Introduction to Python
Lecture 2 Python Programming & Data Types
Introduction to JavaScript for Python Programmers
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Lecture 2 Python Programming & Data Types
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
G. Pullaiah College of Engineering and Technology
PHP an introduction.
General Computer Science for Engineers CISC 106 Lecture 03
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

C463 / B551 Artificial Intelligence Dana Vrajitoru Python

Python Introduction An interpreted, compiled, and interactive, object- oriented, dynamic, imperative, and open source programming language. Created in early 90's by Guido von Rossum at Stichting Mathematisch Centrum in the Netherlands. The name comes from the Monty Python and not from the snake. There is a big community of Python programmers, with conferences and magazines: Web site:

Features of Python Interactive: one can launch a Python console and run instructions directly it. Portable: available on most existing systems. It only requires a C compiler to be ported to any new platform. Structure: functions, classes, modules. It is easy to embed Python with C and C++. The user can write their own code in C or C++ and compile it as Python modules or functions. That makes Python extensible. Usual applications: scripts including CGI scripts, GUIs, scientific computing. Many existing libraries for all sort of purposes.

Syntax Rules The syntax is designed to be simplified as compared to other languages like C/C++. Every compound instruction ends with ":" There are no blocks of code; blocks are implicitly created by indentation. Expressions: usual arithmetic operators, named logic operators: and, or, not. Assignments use the = sign but they don't have to end with ";" Comments start with # as in shell scripting. Variables are declared by assigning them a value and they are local to the block where they appear first.

Control Structures Conditional: if condition: instructions elif condition: #* instructions else: # optional instructions Loops: while condition: instructions else: # optional instructions for var in S: instructions else: # optional instructions for i in range(n): instructions

Built-in Data Structures Lists: linked lists implementing the subscript operator: x = [1,2,3] x.append(4) print x[2] # result: 3 Tupples: constant kind of arrays x = (1,2,3) Dictionaries: association lists x = {} x["word"] = reference for k in x.keys(): print x[k]

Functions and Parameters Function definition: def function_name (par1, par2,...): body of the function It supports default values for parameters. All parameters are value parameters. Any variable storing a complex data structure contains a reference to it. Any changes to the content of such a data structure in the function will affect the variable passed in the function call. Assignments involving a complex data structure don't make a copy of it.

More Built-in Functions Function type: returns the type of an object. type(0) – returns type(0) – returns Checking if something is an integer: if type(x) == type(0):... Reading a value from the terminal: input() x = input() Returning a value from a function: return True Artificial Intelligence – D. Vrajitoru

Example of Conditional def check_type(x): if type(x) == type(0): if type(x) == type(0): print x, "is an integer" print x, "is an integer" elif type(x) == type(1.0): elif type(x) == type(1.0): print x, "is a float" print x, "is a float" elif type(x) == type(""): elif type(x) == type(""): print x, "is a string" print x, "is a string" elif type(x) == type([]): elif type(x) == type([]): print x, "is an array" print x, "is an array" Artificial Intelligence – D. Vrajitoru

Example of while/else def Euler(a, b): if b==0: if b==0: return a return a r = a % b r = a % b while r: while r: a = b a = b b = r b = r r = a % b r = a % b else: else: print "a divisible by b" print "a divisible by b" return b return b return r return r Artificial Intelligence – D. Vrajitoru

Booleans Truth values: True and False. False is equivalent with 0, and empty list [], an empty dictionary {}. Anything else is equivalent to True. Example: x = 0 if not x: print “0 is False” Artificial Intelligence – D. Vrajitoru

Default Values for Parameters Default values: def function (var1 = value, var2 = value,...): Just like in C++, all the parameters that have default values must be grouped at the end. def GCD1(a=10, b=20):... GCD1() -> 10 GCD1(125) -> 5 GCD1(12, 39) -> 3 Artificial Intelligence – D. Vrajitoru

Variables and Scope Module: one python file. Global scope: exists in the module in which they are declared. Local scope: local to the function inside which it is declared. Global variables in a module can be accessed from somewhere else using the notation module.variable. Example: string.digits contains ‘ ’. Artificial Intelligence – D. Vrajitoru

Example Scope def test_scope(): for i in range(4): for i in range(4): for j in range (3): for j in range (3): x = i*10+j x = i*10+j if x>20: if x>20: print x, print x, print x print xtest_scope() Artificial Intelligence – D. Vrajitoru

Try - Except Try: attempts to execute an instruction. If the operation is successful, it moves on. If not, we have the option of doing something else with the instruction except: Another option: except error_type: which does something only for a particular type of exception. Artificial Intelligence – D. Vrajitoru

def scope1(): y = 15 y = 15 y = 20 def scope2(): y = 25 y = 25 def scope3(): try: try: print y print y except: except: print "cannot access global y" print "cannot access global y" print days print days y = 25 y = 25 print y print y days=["monday", "tuesday"] Artificial Intelligence – D. Vrajitoru