session 1
play

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


  1. Session 1 SCRIPTING LANGUAGES 08-10-2018 WEN-CHI YANG

  2. Your first program

  3. Find the file 2. Click here 3. Copy the path 1. Find the file

  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

  5. Find the file 5. type python <filename> to execute your program

  6. REPL READ-EVALUATE-PRINT-LOOP

  7. Read-Evaluate-Print-Loop ➢ An interactive program ➢ Useful for testing short snippets of Python code ➢ Type quit() to stop REPL

  8. Classroom Exercises

  9. Comments ➢ Everything behind # is ignored ➢ Exercise 1

  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

  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 P Q not P P and Q P or Q F F T F F F T T F T ➢ Exercise 3 T F F F T T T F T T

  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

  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

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

  15. Challenge exercise: painting

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend