Session 1 SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG Your first - - PowerPoint PPT Presentation

session 1
SMART_READER_LITE
LIVE PREVIEW

Session 1 SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG Your first - - PowerPoint PPT Presentation

Session 1 SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG Your first program Find the file 2. Click here 3. Copy the path 1. Find the file Find the file 4. Go to the folder where your file locates by using cd Check if your file is here by using


slide-1
SLIDE 1

Session 1

SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG

slide-2
SLIDE 2

Your first program

slide-3
SLIDE 3

Find the file

  • 2. Click here
  • 3. Copy the path
  • 1. Find the file
slide-4
SLIDE 4

Find the file

  • 4. Go to the folder where your file locates by using cd

Check if your file is here by using ls

slide-5
SLIDE 5

Find the file

  • 5. type python <filename> to execute your program
slide-6
SLIDE 6

REPL

READ-EVALUATE-PRINT-LOOP

slide-7
SLIDE 7

Read-Evaluate-Print-Loop

➢ An interactive program ➢ Useful for testing short snippets of Python code ➢ Type quit() to stop REPL

slide-8
SLIDE 8

Classroom Exercises

slide-9
SLIDE 9

Comments

➢ Everything behind # is ignored ➢ Exercise 1

slide-10
SLIDE 10

Data types

➢ Booleans : True, False ➢ Integers : …, -2, -1, 0, 1, 2, 3, … ➢ Floating-point numbers : 1.0, 0.33, -3.14159, …. ➢ Strings : “Hello world!” ➢ Exercise 2

slide-11
SLIDE 11

Boolean Operators

➢ not True is False, not False is True ➢ P and Q is True only when both P and Q are True ➢ P or Q is True when either P or Q is True ➢ Exercise 3

P Q not P P and Q P or Q F F T F F F T T F T T F F F T T T F T T

slide-12
SLIDE 12

String Formatting

➢ %s for strings ➢ %d for integers ➢ %f for floating numbers ➢\n inserts a line break, \t inserts a tab ➢ Exercise 4.1 & 4.2

slide-13
SLIDE 13

Datetime

➢ today = datetime.date.today() # an object ➢ today.day # an attribute ➢ today.month ➢ today.year ➢ Similar for datetime.datetime.now() ➢ exercise 5.1 & 5.2

slide-14
SLIDE 14

String concatenation

➢ Use + to concatenate strings, e.g. “hello” + “ world!” ➢ Try to print a digit with %d, %2d and %02d ➢ Observe ➢ Exercise 6

slide-15
SLIDE 15

Challenge exercise: painting