Xiaojuan Cai Computational Thinking 1 Lecture 2 Simple Programs Xiaojuan Cai (蔡小娟) Fall, 2015.

Slides:



Advertisements
Similar presentations
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
Advertisements

Python Basics: Statements Expressions Loops Strings Functions.
MATLAB & Its Applications In Engineering 胡章芳
Adapted from John Zelle’s Book Slides
Python Programming: An Introduction to Computer Science
CSC 110 Writing simple programs [Reading: chapter 2] CSC 110 C 1.
Vahé Karamian Python Programming CS-110 CHAPTER 2 Writing Simple Programs.
Game Theory 窦衍旭. 什么是博弈论 博弈论,经济学中很著名的理论, 就是在 信息不对称的情况下根据对手可能作出的 决策作出决策,通俗地说,如果我这样做, 那么对手会怎样做,而对手基于我的做法 作出决策,我又该怎么做来应对。
1 为了更好的揭示随机现象的规律性并 利用数学工具描述其规律, 有必要引入随 机变量来描述随机试验的不同结果 例 电话总机某段时间内接到的电话次数, 可用一个变量 X 来描述 例 检测一件产品可能出现的两个结果, 也可以用一个变量来描述 第五章 随机变量及其分布函数.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Chapter 2 Writing Simple Programs
Computer Science 111 Fundamentals of Programming I Iteration with the for Loop.
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.
Program State and Program Execution CSE 1310 – Introduction to Computers and Programming 1.
Computer Science 101 Introduction to Programming.
CS190/295 Programming in Python for Life Sciences: Lecture 2 Instructor: Xiaohui Xie University of California, Irvine.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 2 Elementary Programming.
FUNCTIONS. Function call: >>> type(32) The name of the function is type. The expression in parentheses is called the argument of the function. Built-in.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
Computer Science 101 Introduction to Programming.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Computer Science 101 Introduction to Programming.
很久以前,有个孤儿叫小雪,她很喜欢画画,可是她很穷 沒有钱买笔 。. 有一天晚上,小雪梦见一位老奶奶送给她一枝 又大又长的毛笔。
Chapter 1. Objectives To provide examples of computer science in the real world To provide an overview of common problem- solving strategies To introduce.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
COSC 235: Programming and Problem Solving Ch. 2: Your first programs!!! Instructor: Dr. X.
Variables, Expressions and Statements
请同学们仔细观察下列两幅图有什么共同特点? 如果两个图形不仅形状相同,而且每组对应点所在的直线 都经过同一点, 那么这样的两个图形叫做位似图形, 这个点叫做位 似中心.
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Xiaojuan CaiComputational Thinking1 Lecture 4 Computing with Strings Xiaojuan Cai (蔡小娟) Fall, 2015.
Xiaojuan Cai Computational Thinking 1 Lecture 8 Loop Structure Xiaojuan Cai (蔡小娟) Fall, 2015.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
Xiaojuan Cai Computational Thinking 1 Lecture 6 Defining Functions Xiaojuan Cai (蔡小娟) Fall, 2015.
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Xiaojuan Cai Computational Thinking 1 Lecture 7 Decision Structure Xiaojuan Cai (蔡小娟) Fall, 2015.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Xiaojuan Cai Computational Thinking 1 Lab 中院 305 做 ppt ,讲解 5 分钟 做了什么 怎么做 角色分工 演示一下.
人 有 悲 欢 离 合, 月有阴晴圆缺。月有阴晴圆缺。 华师大版七年级数学第二册 海口市第十中学 数学组 吴锐.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 2.
Chapter 2 Writing Simple Programs
CMSC201 Computer Science I for Majors Lecture 03 – Variables
Topic: Iterative Statements – Part 1 -> for loop
Python: Experiencing IDLE, writing simple programs
Input and Output Upsorn Praphamontripong CS 1110
Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science
Lecture 3 Computing with Numbers
Think What will be the output?
Section 3.2c Strings and Method Signatures
Lecture2.
Chapter 2 Elementary Programming
Chapter 2 Elementary Programming
Python Primer 2: Functions and Control Flow
First Python Program Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An.
“If you can’t write it down in English, you can’t code it.”
CS190/295 Programming in Python for Life Sciences: Lecture 2
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
15-110: Principles of Computing
Loops and Simple Functions
Control Operations Basic operations are input, output, arithmetic, etc. Control operations allow for sequencing other operations Choose between several.
Chopin’s Nocturne.
The Last of the Mohicans (大地英豪)
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Xiaojuan Cai Computational Thinking 1 Lecture 2 Simple Programs Xiaojuan Cai (蔡小娟) Fall, 2015

Xiaojuan Cai Computational Thinking 2 Objectives To be able to understand and write Python statements : to output information to the screen, assign values to variables, get numeric information entered, and perform a counted loop

Xiaojuan Cai Computational Thinking 3 Roadmap The software development Elements of program Names expressions Output statements Assignment statements Definite loop

Xiaojuan Cai Computational Thinking 4 Software development Analyze the problem Determine specifications Create a design (algorithm) Implement the design Test/Debug the program Maintain the program

Xiaojuan Cai Computational Thinking 5 Example Susan 刚刚来到中国,她什么都喜欢,唯独 不喜欢中国的天气预报,因为她习惯华氏度 ( Fahrenheit ),不习惯摄氏度( Celsius )。 她请求你的帮助,她告诉你,华氏和摄氏之 间的转换是线性的,而且 0 摄氏度 =32 华氏度, 100 摄氏度 =212 华氏度。

Xiaojuan Cai Computational Thinking 6 Roadmap The software development Elements of program Names Expressions Output statements Assignment statements Definite loop

Xiaojuan Cai Computational Thinking 7 Names File (module) has name, e.g. converter Function has name, e.g. main Variable has name, e.g. Celsius Names are called identifier.

Xiaojuan Cai Computational Thinking 8 Identifier begin with a letter or underscore _ followed by any sequence of letters, digits, or underscores. Case sensitive All these are legal identifiers: x, celsius, Spam, SPAM, x2, x_2, _x_2_, …

Xiaojuan Cai Computational Thinking 9 Reserved words

Xiaojuan Cai Computational Thinking 10 Expressions The fragments of code that produce or calculate new data values are called expressions, including literals, e.g. 3.9, 32 identifier, e.g. celsius, x combining simple ones with operators, e.g. 3.9*x*(1-x) function calls (later in this course) …

Xiaojuan Cai Computational Thinking 11 Output statement print print,, …, print,, …,, Syntax: <> is slots for other fragments, alternative … indicate any number of Semantics: evaluate, output the value

Xiaojuan Cai Computational Thinking 12 Assignment statement Syntax: = E.g., x = 3.9 * x * (1-x), x = 2 A variable can be assigned many times, with any values (of any types) Semantics: x = x x 11 x 10 “x” x = “x”

Xiaojuan Cai Computational Thinking 13 Assigning input Syntax: = input( ) : prompt the user for input E.g., x = input("Enter a number ") Semantics: evaluate, wait for an input and assign the input to

Xiaojuan Cai Computational Thinking 14 Simultaneous assignment Syntax:,…, =, …, Semantics: evaluate all the ’s, assign the values to corresponding ’s. E.g., x,y = 3,4; x,y = y,x x,y = input(“…”)

Xiaojuan Cai Computational Thinking 15 Definite loop -- syntax for in : is called loop index is any sequence of statements, indenting under the heading consists of list of values

Xiaojuan Cai Computational Thinking 16 Loops A definite loop will execute definite times. The most common definite loop is counted loop. for in range( ): is one of counted loops

Xiaojuan Cai Computational Thinking 17 Definite loop -- semantics

Xiaojuan Cai Computational Thinking 18 Example One more example – Future values Susan 在中国银行存了一笔钱,根据 中国银行的年利率,她想知道 10 年后 她能取出多少钱。

Xiaojuan Cai Computational Thinking 19 Formalize Program Future value Inputs: principal the amount of money initially apr the annual percentage rate Output: the value after 10 years

Xiaojuan Cai Computational Thinking 20 Algorithm Print an introduction Input principal and apr Repeat 10 times: principal = principal * (1 + apr) Output the principal

Xiaojuan Cai Computational Thinking 21 Conclusion def main(): print "This program illustrates a chaotic function" x = input("Enter a number between 0 and 1: ") for i in range (10): x = 3.9 * x * (1-x) print i,x main() Circle each identifier. Underline each expression. indicate the type of statement on each line