Python入门教程1
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Programming Languages
• Low-level: add $t0, $t1, $t2
– Define individual, machine readable instructions
• High-level: x=y+z
– Human readable instructions translated into machine readable instructions
Why Python?
• • • • • • Freely available Cross platform Widely adopted Well documented Designed for teaching Beautiful
A set of instructions a computer executes to achieve a goal is called… a) a process. b) a program. c) a procedure. d) a pronoun.
• Exponentiation
– Symbol: ** – Description: base to the exponent power – Example: 3**2
Instructions
• Programs are data. • Instructions are encoded in binary. • Each instruction is typically 4 or 8 bytes.
Programming Language
• An artificial language used to communicate instructions to a computer • Rigorous and unambiguous • Grammar is mathematically formal • Has syntax and semantics like a natural language
Data
• Information stored in a computer is called data. • All data is represented in binary.
– A series of 0’s and 1’s
• Each 0 or 1 is called a bit. • Bits are stored in groups of 8 called bytes.
• Office hours (on RELATE)
– Have specific questions if you want assistance
Course Overview
• ≈ 4-5 weeks: programming (Python) • ≈ 2-3 weeks: engineering programming • 1 week: Matlab
• Can also find it via CoE course directory
– https://courses.engr.illinois.edu
Labs
• • • • Start tomorrow Intended to get hands on experience First learn basics of Unix command line Then learn some programming basics
WHAT IS PROGRAMMING?
Program
• A set of instructions a computer executes to achieve a goal • Can be very long (millions of instructions) • Also called “code” or “source code” • Our programs will be called “scripts”
• Never copy code
Getting help
• Piaz来自百度文库a
– Be civil to peers and staff – All posts containing solutions should be made private – A privilege, not a right
High-level languages
• Compiled languages
– Compiler translates entire program into machine language
• Interpreted (scripting)
– Interpreter translates program into machine language line by line – Translation happens “on the fly”
BASIC PYTHON SYNTAX AND SEMANTICS
Computer
Computer
Processor
Literals
• Describe data that doesn’t change • ANALOGY: Literals are nouns in Python • Represent a fixed value (e.g. 3 or 5,136,833,998)
A grouping of 8 bits is called… a) a nibble. b) a chomp. c) a byte. d) a gobble.
Python is… a) a high-level language. b) a low-level language.
Python is… a) a compiled language. b) an interpreted language.
CS101: Intro to Computing Summer 2016
Week 1
Administrivia
• Homework 1 is posted (due Friday)
Administrivia
• i>clicker
– Wednesday and Friday i>clicker tests – After that, i>clicker attendance – Need to register device ON COURSE COMPASS PAGE
Computer
Processor 3
Computer 3
Processor
Operators
• Describe how to manipulate data • ANALOGY: Operators are the verbs of Python • Common mathematical operators (e.g. +, , *, /) are operators • There are many more operators
Everyone can program
• Our goal is a safe, friendly, inclusive atmosphere for everyone to learn. • You should feel welcome, regardless of gender, gender identity, ethnicity, nationality, religion, disability, sexual orientation, class, political views, or educational background. • We are peers and allies. Let’s all treat one another with respect and kindness.
Evaluate this expression: 23+6/2-4 a) 22 b) 18 c) -9 d) None of the above
Other operators
• Modulo YES, THIS IS IMPORTANT!
– Symbol: % – Description: remainder after division – Example: 9%2
Required Supplies
• No textbook! • i>clicker • CodeLab account
Course website
• https://relate.cs.illinois.edu/course/SU2016CS101/
– Homework assignments – Course calendar – Course policies
HOW WILL THIS CLASS WORK?
Grading
• • • • • 20% homework 25% labs 10% lecture attendance (i>clicker) 20% midterms (2) 25% final exam
Official grade book will be on Compass
Programming is a skill!
• • • • • Learn by doing! Learn by interacting! You need to constantly practice. Get help when you need it! WARNING: If you are not committed to this class, you’re not going to make it!
Computer
Processor +
Computer WTF?
Processor
Expressions
• Combining constants and operators, we can build expressions • ANALOGY: Expressions are sentence fragments in Python • Expressions are evaluated to produce a new value (e.g. 3*5 or 23-100) • Expressions can be very complicated (e.g. 3+8*5+4-7/100)
Policies
• No late homework submissions • All machine generated grades are final • Late registrants should keep up with work
– No extensions or exceptions for late registration
WHY ARE WE HERE?
I’ve seen things you people wouldn’t believe…
Everyone should program!!!
• This is my mission!
Why learn to program?
a. b. c. d. e. Pervasive Lucrative Transferrable Creative Self-determination
Python
• • • • High-level language Interpreted language Strongly, dynamically typed language WARNING: Split between versions 2 and 3. We will use version 3!
Computer
Processor 3*5
Computer 15
Processor
Order of Operations
• 1+1*2
a) 4 b) 3 c) None of the above
• Like math, Python has order of operations • Not always intuitive • When in doubt, use parentheses!