中国高校课件下载中心 》 教学资源 》 大学文库

上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture03 CONDITIONALS AND SEQUENCES Strings, lists and file objects

文档信息
资源类别:文库
文档格式:PDF
文档页数:53
文件大小:817.62KB
团购合买:点击进入团购
内容简介
• Boolean expressions • Conditionals – Simple decisions – Chained conditionals – Nested conditionals • Sequences – Strings – Lists • File objects
刷新页面文档预览

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Computational Thinking and Approach Lecture 3 Dr.Jialiang LU Jialiang.lu@situ.edu.cn

Computational Thinking and Approach Lecture 3 Dr. Jialiang LU Jialiang.lu@sjtu.edu.cn 1

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Strings,lists and file objects CONDITIONALS AND SEQUENCES 2

CONDITIONALS AND SEQUENCES Strings, lists and file objects 2

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Out ines ·Boolean expressions 。Conditionals -Simple decisions -Chained conditionals Nested conditionals ·Sequences -Strings Lists ·File objects 3

Outlines • Boolean expressions • Conditionals – Simple decisions – Chained conditionals – Nested conditionals • Sequences – Strings – Lists • File objects 3

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Build-in Types 。Numbers: int,long float bool complex o Sequences: -str list,tuple ·Mappings: dict 4

Build -in Types • Numbers: – int, long – float – bool – complex • Sequences: – str – list,tuple • Mappings: – dict 4

上游通大¥ ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Boolean expressions 。True of False With relational operators Applied on string type as well Python Mathematics Meaning = 2 Greater than or equal to > > Greater than != 卡 Not equal to 5

Boolean expressions • True of False • With relational operators – Applied on string type as well 5

上游充通大学 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Logical operators 。and,or,not >>>X=5 >>>x%2==00rx%5==0 True >>>x%2==0andx%5==0 Fals a and b a b a or b a b not a a False False False False False False True False False False True True False True False True False True False True True False True True True True True True 6

Logical operators • and, or, not >>> x = 5 >>> x%2 == 0 or x%5 == 0 True >>> x%2 == 0 and x%5 == 0 Fals 6

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY True or False True:1,!=0 not empty (string) ·False:0 Operation Result Notes x or y if x is false,then y,else x (1) X and y if x is false,then x,else y (2) not x if x is false,then True,else (3) False ·>>>a=3 ·>>>a==True ·False Why!!! 7

True or False • True: 1, !=0 not empty (string) • False: 0 • >>>a=3 • >>>a==True • False Why!!! 7

图 上游通大¥ ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Simple Decisions if : yes true? no 8

Simple Decisions 8

上游通大¥ ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Two-Way Decisions if : else: 10 yes condition statements 2 statements 1 9

Two-Way Decisions 9

上游充通大 ParisTech SHANGHAI JIAO TONG UNIVERSITY INSTITUT DES SCIENCES ET TECHNOLOGIES PARIS INSTITUTE OF TECHNOLOGY Examples printParity (x) no yes X%2==0 print x,"is odd" print x,"is even" def printparity(x): ifx号2==0: print x,"is even" else: print x,"is odd< printparity() 10

Examples 10 def printParity(x): if x%2 == 0: print x, "is even" else: print x, "is odd« printParity()

刷新页面下载完整文档
VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
相关文档