Algorithms Programming with Python

34 2 0
Algorithms  Programming with Python

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

PowerPoint Presentation Algorithms Programming with Python Python Level 1 – Lesson 1 Nguyễn Chí Thức gthuComputer programs 2 • A computer.PowerPoint Presentation Algorithms Programming with Python Python Level 1 – Lesson 1 Nguyễn Chí Thức gthuComputer programs 2 • A computer.

Algorithms & Programming with Python Python Level – Lesson Nguyễn Chí Thức gthuc.nguyen@gmail.com 0986636879 Computer programs • A computer program is a set of instructions (commands) that causes a computer to perform some kind of action • Software is a collection of computer programs Programming languages • A programming language is simply a particular way to talk to a computer—a way to use instructions that both humans and the computer can understand • We use in this course: Python • Later in this course: Pascal Installing python (on Windows) • https://www.python.org/downloads/ • > python >>> print("Hello World") >>> Ctrl+Z Default IDE: • > idle.bat Wing IDE • http://www.wingware.com/downloads/wing-personal repl.it https://repl.it/ repl.it https://repl.it/ https://repl.it/repls https://repl.it/repls https://repl.it/repls https://repl.it/repls Arithmetic operators >>> >>> >>> >>> 4.5 * 3.8 2017 + 2018 * (2017 + 2018) * ((3 + 7) * 10) / + Addition - Subtraction * Multiplication / Division % Modulus ** Exponent // Integer division 10 Multiline string • How to output this paragraph? Good morning! How is it going? • Try this? message = "Good morning! How is it going?" print(message) 20 Multiline string • How to output this paragraph? Good morning! How’s it going?  Using three single quotes (or three double quotes) message = '''Good morning! How is it going?''' print(message) 21 String with quote inside • How to output this string? I’m good • Try this? message = 'I'm great' print(message) 22 String with quote inside • How to output this string? I’m good message = "I'm great" print(message) message = 'I\'m great' print(message) message = '''I'm great''' print(message) 23 String with quote inside • How about this string? He said, "I’d like a cup of tea" • • • • Using single quote? Using double quote? Using three single quotes? Escaping with backslash (\)? 24 Concatenate strings msg1 = 'Hello ‘ msg2 = ', how are you?‘ name = 'Thuc‘ print(msg1 + name + msg2) 25 Data types – string and integers Strings 'python' "programming" """ This is a sample of multiline string ""“ Integers 12 543 214 * 5233 352 // 34 452 % 12 "hello" + " world“ "My number is " + str(12345) 26 Data types - float Floats 12.0 543.12 214.0 * 5233 352 / 34 131.12 – 124.31 27 String + Integer? msg1 = 'Hello ‘ msg2 = 123 print(msg1 + msg2) 28 String + Integer? msg1 = 'Hello ‘ msg2 = str(123) print(msg1 + msg2) 29 Embedding values in string message = 'Hello Peter, how are you?' print(message) message = 'Hello John, how are you?' print(message) 30 Embedding values in string • To display a message using the contents of a variable • Using: %s message = 'Hello %s, how are you?' print(message % 'Peter') print(message % 'John') 31 Embedding values in string a = 100 b = 10 message = '%s is divisible by %s.' print(message % (100, 10)) 32 Multiplying strings Try this: print(10 * 'a') > aaaaaaaaaa spaces = ' ' * 25 print('%s Python programming' % spaces) 33 Comments # this is the first comment spam = # and this is the second comment # and now a third! text = "# This is not a comment" """ Multiline comment """ 34 ... computer can understand • We use in this course: Python • Later in this course: Pascal Installing python (on Windows) • https://www .python. org/downloads/ • > python >>> print("Hello World") >>> Ctrl+Z... computer to perform some kind of action • Software is a collection of computer programs Programming languages • A programming language is simply a particular way to talk to a computer—a way to use... it going?''' print(message) 21 String with quote inside • How to output this string? I’m good • Try this? message = 'I'm great' print(message) 22 String with quote inside • How to output this

Ngày đăng: 27/10/2022, 10:49

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan