Intro to Python. Python is an interpreted language Can be used interactively Identifiers are case-sensitive Operators: + - * / ** Arbitrarily large integer.

Slides:



Advertisements
Similar presentations
Introduction to Python Week 15. Try It Out! Download Python from Any version will do for this class – By and large they are all mutually.
Advertisements

Python Lab: Fundamentals Proteomics Informatics, Spring 2014 Week 3 11 th Feb, 2014
Adapted from John Zelle’s Book Slides
Python Programming: An Introduction to Computer Science
Vahé Karamian Python Programming CS-110 CHAPTER 2 Writing Simple Programs.
Line Efficiency     Percentage Month Today’s Date
Python Programming: An Introduction to Computer Science
Structured programming
Introduction to Python
Chapter 2 Writing Simple Programs
Intro to Python Paul Martin. History Designed by Guido van Rossum Goal: “Combine remarkable power with very clear syntax” Very popular in science labs.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Python.
INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
The Python Programming Language Jeff Myers Programming Language Concepts, 01/14/2002
Data Collections: Dictionaries CSC 161: The Art of Programming Prof. Henry Kautz 11/4/2009.
Data Types Integer 15 StringHelloThere! Float/Real BooleanYes / No CharP.
STANDARD FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Python Jim Eng Vote on class policy In lecture we discussed several ways in which you might show credits for content in the web pages.
Neal Stublen Computer Memory (Simplified)  Remember, all programming decisions came down to a true or false evaluation  Consider.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Input and Output CMSC 120: Visualizing Information Lecture 4/10.
Decision Making. Alter the flow of the program Conditionally controlling execution of a set of commands if -statement: if a > b: print a.
I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )
Python Basics  Values, Types, Variables, Expressions  Assignments  I/O  Control Structures.
The Birthday Paradox July Definition 2 Birthday attacks are a class of brute-force techniques that target the cryptographic hash functions. The.
CSx 4091 – Python Programming Spring 2013 Lecture L2 – Introduction to Python Page 1 Help: To get help, type in the following in the interpreter: Welcome.
PYTHON PROGRAMMING. WHAT IS PYTHON?  Python is a high-level language.  Interpreted  Object oriented (use of classes and objects)  Standard library.
Input, Output and Variables GCSE Computer Science – Python.
Chapter 2 Writing Simple Programs
Jan 2016 Solar Lunar Data.
Presented By S.Yamuna AP/IT
Q1 Jan Feb Mar ENTER TEXT HERE Notes
Introduction to Python

Average Monthly Temperature and Rainfall
Introduction to Python
CMSC201 Computer Science I for Majors Lecture 07 – Strings and Lists
2017 Jan Sun Mon Tue Wed Thu Fri Sat
Gantt Chart Enter Year Here Activities Jan Feb Mar Apr May Jun Jul Aug
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
Jan Sun Mon Tue Wed Thu Fri Sat
©G Dear 2008 – Not to be sold/Free to use
Electricity Cost and Use – FY 2016 and FY 2017
Class 13 function example unstring if if else if elif else
Python Basics with Jupyter Notebook
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
Chopin’s Nocturne.

Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
Text for section 1 1 Text for section 2 2 Text for section 3 3
More Basics of Python Common types of data we will work with
TIMELINE NAME OF PROJECT Today 2016 Jan Feb Mar Apr May Jun
Q1 Q2 Q3 Q4 PRODUCT ROADMAP TITLE Roadmap Tagline MILESTONE MILESTONE
COMPUTING.
Python Reserved Words Poster
Presentation transcript:

Intro to Python

Python is an interpreted language Can be used interactively Identifiers are case-sensitive Operators: + - * / ** Arbitrarily large integer

Python Reserved Words and assert break class continue def del elif else except exec finally for from global if import in is lambda not or pass print raise return try while yield

Output Statements print () print (,,..., )

print (3+4) print (3, 4, 3 + 4) print () print (“The answer is”, 3+4)

Assignment Statements = = input( ) = raw_input( ),,... =,,...,

x = 5 y = 3.9 * x * (1 - x) age = input(“Your age?”) name = raw_input(“Your name?”) x, y = y, x

Decisions if : elif : else: = > !=

if x > 5: print “greater than five” elif x < 5: print “less than five” else: print “five”

Definite Loops for in :

Sequences/Lists [0, 1, 2, 3] [1, 3, 5, 7, 9] range(10) range( )

for i in [0, 1, 2, 3]: print i for i in range(11): print i

Indefinite Loops while :

i=0 while i <= 10: print i i = i + 1

Strings greet = “Hello Bob” str2 = ‘spam’ print greet, str2 greet[0] greet[-1] greet[-3] greet[5:9] greet[:5] greet[5:]

More with Strings greet = “Hello Bob” str2 = ‘spam’ greet + str2 3 * str2 (3 * str2) + (greet * 2) len(greet) for ch in greet: print ch,

String and List Operations + Concatenation * Repetition [] Indexing [:] Slicing len( ) Length for in Iteration

[1, 2] + [3, 4] [1, 2] * 3 grades = [‘A’,’B’,’C’,’D’,’F’] grades[0] grades[2:4] len(grades)

More with Lists.append(x).sort().reverse().index(x).insert(i, x).count(x).remove(x).pop(i)

Other String Operations import string string.capitalize( ) string.capwords( ) string.lower( ) string.upper( ) string.replace(,, ) string.center(, ) string.count(, ) string.find(, ) string.join( ) string.split( )

Math Library pi e sin(x) cos(x) tan(x) asin(x) acos(x) atan(x) log(x) log10(x) exp(x) ceil(x) floor(x)

Functions def ( ):

def main(): celsius = input("What is the Celsius temperature? ") fahrenheit = (9.0 / 5.0) * celsius + 32 print "The temperature is ", fahrenheit, " degrees Fahrenheit." main()

def happy(): print “Happy birthday to you!” def sing(person): happy() print “Happy birthday, dear”, person + “.” happy() def main(): sing(“Fred”) print sing(“Lucy”) print sing(“Elmer”) main()

import math def main(): print “This program finds the real solutions to a quadratic” print a, b, c = input(“Please enter the coefficients (a, b, c): “) discRoot = math.sqrt(b * b - 4 * a * c) root1 = (-b + discRoot) / (2 * a) root2 = (-b - discRoot) / (2 * a) print print “The solutions are:”, root1, root2 main()

def main(): # months is used as a lookup table months = “JanFebMarAprMayJunJulAugSepOctNovDec” n = input(“Enter a month number (1-12): “) # compute starting position of month n in months pos = (n-1) * 3 # grab the appropriate slice from the month monthAbbrev = months[pos:pos+3] # print the result print “The month abbreviation is”, monthAbbrev + “.” main()

def main(): # months is a list used as a lookup table months = [“Jan”, “Feb”, “Mar”, “Apr”, “May”, “Jun”, “Jul”, “Aug”, “Sep”, “Oct”, “Nov”, “Dec”] n = input(“Enter a month number (1-12): “) # print the result print “The month abbreviation is”, month[n-1] + “.” main()

File Basics = open(, ).read().readline().readlines().write( )

import string def main(): fname = raw_input(“Enter a filename: “) infile = open(fname, ‘r’) data = infile.read() DATA = string.upper(data); outfile = open(fname + “_CAP”, ‘w’) outfile.write(DATA) main()

Dictionaries [ ] passwd = {} for line in open(‘passwords’, ‘r’): user, pass = string.split(line) passwd[user] = pass

Dictionaries.has_key( ) in.keys().values().items().get(, ) del [ ].clear()