Welcome to Python 3. Some history

Similar documents
Algorithms and Programming I. Lecture#12 Spring 2015

CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Python Input, output and variables

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Winter 2019 CISC101 1/17/2019

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

Computer Programming : C++

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Java Bytecode (binary file)

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Python Unit

Full file at

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Computer Components. Software{ User Programs. Operating System. Hardware

Chapter 2: Programming Concepts

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Elementary Programming

Welcome to Python! Ilhoe Jung. Graphics & Media Lab

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Engineering Problem Solving with C++, Etter/Ingber

Topic 2: Introduction to Programming

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Introduction to computers and Python. Matthieu Choplin

SOFT 161. Class Meeting 1.6

CS 177 Recitation. Week 1 Intro to Java

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Computer Science II Lecture 1 Introduction and Background

>>> * *(25**0.16) *10*(25**0.16)

Lecture 1. basic Python programs, defining functions

Objectives. In this chapter, you will:

Computer Components. Software{ User Programs. Operating System. Hardware

Table of Contents EVALUATION COPY

The C++ Language. Arizona State University 1

Chapter 2. Outline. Simple C++ Programs

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Section 2.2 Your First Program in Java: Printing a Line of Text

Programming Basics. Part 1, episode 1, chapter 1, passage 1

Object-Oriented Programming

Assignment Marking Criteria

Introduction to Java Applications

Getting Started Values, Expressions, and Statements CS GMU

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Week One: Introduction A SHORT INTRODUCTION TO HARDWARE, SOFTWARE, AND ALGORITHM DEVELOPMENT

IT 374 C# and Applications/ IT695 C# Data Structures

And Parallelism. Parallelism in Prolog. OR Parallelism

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

COMP 202 Java in one week

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

COMP 202 Java in one week

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

Topics. Chapter 5. Equality Operators

VBScript: Math Functions

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

CHAPTER INTRODUCTION

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

DOMjudge team manual. Summary. Reading and writing. Submitting solutions. Viewing scores, submissions, etc.

1/11/2010 Topic 2: Introduction to Programming 1 1

AP CS Unit 3: Control Structures Notes

Chapter 2: Basic Elements of C++

Python for Non-programmers

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Programming with Java

BTE2313. Chapter 2: Introduction to C++ Programming

CS11 Java. Fall Lecture 1

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

C++ Programming Lecture 11 Functions Part I

Course Outline. Introduction to java

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

Introduction to Python, Cplex and Gurobi

Getting started with Java

Python Workshop. January 18, Chaitanya Talnikar. Saket Choudhary

Reviewing all Topics this term

CPS122 Lecture: From Python to Java

Key Differences Between Python and Java

COMP 110 Project 1 Programming Project Warm-Up Exercise

Computer Science is...

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

DOMjudge team manual. Summary. Reading and writing. Submitting solutions. Viewing scores, submissions, etc.

Chapter 2: Introduction to C++

BITG 1233: Introduction to C++

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Transcription:

Python 3

Welcome to Python 3 Some history Python was created in the late 1980s by Guido van Rossum In December 1989 is when it was implemented Python 3 was released in December of 2008 It is not backward compatible with Python 2 The Python developers use a simpler syntax than most other programming languages and wanted learning Python to be fun

The Python language is named for the Monty Python Flying Circus not the snake. Although many books have pictures of snakes on the front, my guess is because the authors don t wish to pay the royalties to Monty Python Flying Circus to use it s picture on the cover

The Programming Language Like all languages, Python has a grammar or a syntax. Syntax is the grammar, structure, or order of the elements in a language statement. i.e. blocks of code must be indented, the main program must begin at the left margin, etc i.e. print( the answer is, answer) NO Program can be written to solve an unsolvable problem

Syntax & Grammar Python is intended to be a highly readable language. It is designed to have an uncluttered visual layout; it frequently using English keywords where other languages use punctuation. Python requires less boilerplate than traditional manifestly typed structured languages such as C or Pascal, and has a smaller number of syntactic exceptions and special cases than either of these

Some terms Boilerplate In information technology, a boilerplate is a unit of writing that can be reused over and over without change Case Sensitive Python is a case sensitive language. That means when you name a variable or a module, a.k.a. function, the use all the upper/lowercase letters can change the name of the variable or module; for example the name FIRST is not the same as First, or FiRst, or first

More Syntax & Grammar The simplicity of Python is demonstrated by its version of the classic "Hello world" program: print("hello world") Indentation Python uses whitespace indentation, rather than curly braces or keywords, to delimit blocks; a feature also termed the off side rule. An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block.

Hello World Program in Java class myfirstjavaprog { public static void main(string args[]) { System.out.println("Hello World!"); } }

Hello World in C++ // 'Hello World!' program #include <iostream> int main() { std::cout << "Hello World!" << std::endl; return 0; }

000100 IDENTIFICATION DIVISION. 000200 PROGRAM ID. HELLOWORLD. 000300 000400* 000500 ENVIRONMENT DIVISION. 000600 CONFIGURATION SECTION. 000700 SOURCE COMPUTER. RM COBOL. 000800 OBJECT COMPUTER. RM COBOL. 000900 001000 DATA DIVISION. 001100 FILE SECTION. 001200 100000 PROCEDURE DIVISION. 100100 100200 MAIN LOGIC SECTION. 100300 BEGIN. 100400 DISPLAY " " LINE 1 POSITION 1 ERASE EOS. 100500 DISPLAY "Hello world!" LINE 15 POSITION 10. 100600 STOP RUN. 100700 MAIN LOGIC EXIT..100800 EXIT. Hello World in Cobol

Errors Syntax error an error in the grammar of the language a typo, a wrong indent Logic error an error in the programming logic that is syntactically correct BUT produces the wrong answer. You enter the numbers 6 and 7 and are told the sum is 42 Runtime error an error that causes the program to stop unexpectedly. A number you are dividing by some how becomes 0 and the program crashes You attempt to find the square root of a negative number

Hello World BASIC 10 PRINT "Hello World!"

Programming

Variables A variable is a placeholder in the memory of a computer for data. In Python, variable names usually begin with a lowercase letter and are followed by other letters or the digits zero through nine. Usually, names beginning with capital letters or all capital letters are you reserved for constants. Names that begin with the underscore character are typically used to name modules that relate to some function that is used in Python, in other words system programs.

Examples Valid variable names: price, name, hours, pay, day1_value Invalid variable names: num books, name%, money$

Statements print comments input eval int float

print statement Used to produce output on the computer screen; print is a reserved word and a built in python module. The print statement can have a single item or multiple items to display in a single statement print( this is a string ) or print (c) print( The answer is,h) print( The three values are:,a, b, c)

Comments Comments add descriptions to a program that help the programmer remember what a particular line or lines of code do. Comments are also used to identify who wrote the code and when. # this is a comment in python Comments can begin at the left margin or occur at the end of a line Comments are for PEOPLE only; interpreters and compilers ignore them.

Type this example

input statements Get data from the screen by use of wired or wireless connections price = input( Enter cost of buying 3 items ) When this statement is executed, the value stored in price is assigned as a character to price.

Functions Used Convert In this case strings to numeric values They are: int, float, eval int() returns the integer value of a str. float() returns the real value of the str. eval() evaluates the funtion and determines ho it will work

Assignment statements In Python, like other computer languages, statements are read from left to right. The variable on the left side of the equation is the variable that will hold your answer. On the right side of the is the equation is what needs to be solved Example Payee = hours * wage;

Assignment statement continued Assignment statements come in very many forms throughout the program A single value can be assigned to another variable. letter X= 40 A variable can have the value of the a formula placed the. Y=3X +4 A variable can be a holding place for the answer of a function or module. Y = sqrt(x)

operators

Number types Integers have no decimal point Real numbers have a decimal part Character a single character String a group of characters between single quote or double quotes

Some Facts Order of operations Trig functions sine, cosine, tangent In the math library, which needs to be imported at the beginning of a program. Use the following statement: from math import *