CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

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

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS1110 Lab 1 (Jan 27-28, 2015)

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

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

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

Not-So-Mini-Lecture 6. Modules & Scripts

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Introduction to Python. Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas

Java Bytecode (binary file)

Getting Started Values, Expressions, and Statements CS GMU

CS1 Lecture 3 Jan. 22, 2018

CSE 101 Introduction to Computers Development / Tutorial / Lab Environment Setup

Python Programming Exercises 1

Table of Contents EVALUATION COPY

MEIN 50010: Python Introduction

Part III Appendices 165

Introduction to programming with Python

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

The current topic: Python. Announcements. Python. Python

Chris Simpkins (Georgia Tech) CS 2316 Data Manipulation for Engineers Python Overview 1 / 9

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

CSCI 121: Anatomy of a Python Script

Lecture 1. basic Python programs, defining functions

Senthil Kumaran S

Programming to Python

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

IS12 - Introduction to Programming. Lecture 7: Introduction to C

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

Python for Non-programmers

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

CS 3360 Design and Implementation of Programming Languages. Exam 1

CS558 Programming Languages

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

CSI32 Object-Oriented Programming

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

Python Input, output and variables

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

CS1 Lecture 3 Jan. 18, 2019

Introduction to computers and Python. Matthieu Choplin

assembler Machine Code Object Files linker Executable File

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Course Outline. Introduction to java

Building Java Programs. Introduction to Programming and Simple Java Programs

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

Python Class-Lesson1 Instructor: Yao

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

from scratch A primer for scientists working with Next-Generation- Sequencing data Chapter 1 Text output and manipulation

CSE 115. Introduction to Computer Science I

Babes-Bolyai University

Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors

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

Chapter 2 Getting Started with Python

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Objec+ves. Review. Basics of Java Syntax Java fundamentals. What are quali+es of good sooware? What is Java? How do you compile a Java program?

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

But before understanding the Selenium WebDriver concept, we need to know about the Selenium first.

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

Lecture 1. Types, Expressions, & Variables

Scripting Languages. Diana Trandabăț

One of the hardest things you have to do is to keep track of three kinds of commands when writing and running computer programs. Those commands are:

Life Without NetBeans

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

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Full file at

EL2310 Scientific Programming

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

CS 301. Lecture 05 Applications of Regular Languages. Stephen Checkoway. January 31, 2018

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

GCC C++: Comment Text

Shell / Python Tutorial. CS279 Autumn 2017 Rishi Bedi

Introduction to REXX Programming Language

Programming Environments

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

S206E Lecture 19, 5/24/2016, Python an overview

CS Advanced Unix Tools & Scripting

Python Programming, bridging course 2011

Java: Comment Text. Introduction. Concepts

And Parallelism. Parallelism in Prolog. OR Parallelism

1. The programming language C is more than 30 years old. True or False? (Circle your choice.)

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

Chapter 2. Lexical Elements & Operators

Introduction to Bioinformatics

Introduction to Programming with Python: overview

C H A P T E R 1. Introduction to Computers and Programming

Python. Jae-Gil Lee Based on the slides by K. Naik, M. Raju, and S. Bhatkar. December 28, Outline

Physics 514 Basic Python Intro

Science One CS : Getting Started

CSC105, Introduction to Computer Science I. Introduction. Perl Directions NOTE : It is also a good idea to

CMPS 12A Introduction to Programming Lab Assignment 7

Introduction to Programming: Variables and Objects. HORT Lecture 7 Instructor: Kranthi Varala

CSC Web Programming. Introduction to JavaScript

Programming In Java Prof. Debasis Samanta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Transcription:

CS 133 - Introduction to Computational and Data Science Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

Previous class We have learned the path and file system. Today we are going to learn how to use Atom and get our first Python program! 2

Atom Demo how to open and use Atom 3

Introduction to Python What is Python? Why do people use Python? Python Java Ruby Scala R C C++ C# Scheme Objective C JavaScript Perl Go Swift

Introduction to Python It s free It s portable It s powerful It s mixable

Programming basics code or source code: The sequence of instructions in a program. syntax: The set of legal structures and commands that can be used in a particular programming language. output: The messages printed to the user by a program. console: The text box onto which output is printed. Some source code editors pop up the console as an external window, and others contain their own console window. 6

The Python Interpreter Python is an interpreted language The interpreter provides an interactive environment to play with the language Results of expressions are printed on the screen >>> 3 + 7 10 >>> 3 < 15 True >>> 'print me' 'print me' >>> print 'print me' print me >>>

Compiling and interpreting Many languages require you to compile (translate) your program into a form that the machine understands. source code Hello.java compile byte code Hello.class execute output Python is instead directly interpreted into machine instructions. interpret source code Hello.py output 8

How to run? Python scripts end with.py python test.py python2 test.py Python 2 vs Python 3 print 'Hello, World! vs print(' Hello, World!')

Demo: Hello World Open a terminal window and type python If on Windows open a Python IDE like IDLE At the prompt type hello world! >>> 'hello world!' 'hello world!'

Demo: Hello World In Atom, create a python script: helloworld.py. Let s do it together!

How to run? We need to navigate until we find our file to be able to execute it. To do that we need to open a command prompt window. Type the words cmd in the search bar and click on the command prompt. To find your file you can use the following commands cd name_of_directory to change directory cd.. To go one directory below (Note that there is a space between cd and the 2 dots) dir list all files in the current directory

Handout 2 Let s practice it for a simple Python program!

Comments Documenting your code is very important Use # to write any message that will be ignored by Python. This can also be used to test your code # This is a single line comment is used to have multiline comments This is a multi Lin E Comment

The print statement Elements separated by commas print with a space between them A comma at the end of the statement (print hello,) will not print a newline character >>> print 'hello' hello >>> print 'hello', 'there' hello there

variables In Python, like in other languages, we store values in variables. Unlike other languages, in Python the variables don t have a type Use of single quotes represents text. No quotes represents numbers >>>message = Hello >>>print message >>>message = Hello >>>print message >>>message = Hello >>>print message

Everything is an object Everything means everything, including functions and classes (more on this later!) Data type is a property of the object and not of the variable >>> x = 7 >>> x 7 >>> x = 'hello' >>> x 'hello' >>>

variables Rules of naming a variable: Don t start with numbers Don t use @ or - Don t use reserved words

Practice Can I use the following variable names? 1ab ab@a aaaa3 ABDA2 AND for For a_12a b-32d

Object Type Summary

Numbers: Integers Integer the equivalent of a C long Long Integer an unbounded integer value. >>> 132224 132224 >>> 132323 ** 2 17509376329L >>>

Numbers: Floating Point int(x) converts x to an integer float(x) converts x to a floating point The interpreter shows a lot of digits >>> 1.23232 1.2323200000000001 >>> print 1.23232 1.23232 >>> 1.3E7 13000000.0 >>> int(2.0) 2 >>> float(2) 2.0

Numbers: Floating Point int(10.39) int(100.9999) int(1001.00001) float(87) float(eight)

Numbers: Complex Built into Python Same operations are supported as integer and float >>> x = 3 + 2j >>> y = -1j >>> x + y (3+1j) >>> x * y (2-3j)

Operators Operations in Python are based on sign precedence Image from: http:// www.tutorialspoint.com/ python/ operators_precedence_exa mple.htm

Operators Integer vs float operations Integer operation will result in only the integer part of the operation 5/3 equals 1 Float operation will result in the float value of the operation 5/3.0 equals 1.66666667 5.0/3 equals 1.66666667 5.0/3.0 equals 1.666666667 You can fix that by adding the words: from future import division At the beginning of your code Let s try it together

After class 1. Practice and get familiar with Atom, command prompt 2. Try examples using python, such as Integer, Strings