Think Python :Chapter 5: Conditionals and Recursion 笔记

本文是《Think Python: How to Think Like a Computer Scientist》第5章Conditionals and Recursion的学习笔记,涵盖模数运算符、布尔表达式、逻辑运算、条件执行等概念,并通过递归案例解释了其工作原理。同时,提到了无限递归的危害以及如何获取键盘输入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

这是麻省理工大学(MIT)官方编程教程中Python Tutorial的内容,教材为《Think Python: How to Think Like a Computer Scientist》。这是我的学习笔记,因为水品有限,请大家多多包涵。如果有一起学习的同学可以一起交流。如笔记中错误,请一定要告诉我啊,我肯定及时改正。所有笔记的目录详见:MIT:Python Tutorial目录

这是MIT官方编程教程中Python TutorialUsing if, else, and while的内容。本篇博客为《 Think Python: How to Think Like a Computer Scientist》的第5章 Conditionals and Recursion的笔记内容。(Think Python :Chapter 5: Conditionals and Recursion

Python Tutorial[3]:Using if, else, and while

Before starting these problems, please read(学习材料):
- Think Python, Chapter 5: Conditionals and Recursion, through section 5.7
- Think Python, Chapter 7: Iteration

Chapter 5 Conditionals(条件语句) and recursion(循环递归语句)

5.1 Modulus operator(模数运算符)

modulus operator(模数运算符): An operator, denoted with a percent sign (%), that works on integers and yields the remainder(余数) when one number is divided by another.

5.2 Boolean expressions(布朗运算表达)

boolean expression: An expression whose value is either True or False.
relational operator: One of the operators that compares its operands: == , != , > , < , >= , and <=.
A common error is to use a single equal sign (=) instead of a double equal sign (==). Remember that = is an assignment operator and == is a relational operator. There is no such thing as =< or =>.(=代表数学任务运算,==代表相关运算)

5.3 Logical operators(逻辑运算)

logical operator: One of the operators that combines boolean expressions: and , or , and not .

5.4 Conditional execution(条件运算)

conditional statement: A statement that controls the flow of execution depending on some condition.
condition: The boolean expression in a conditional statement that determines which branch is executed.
compound statement: A statement that consists of a header and a body. The header ends with a colon (:). The body is indented relative to the header.

5.5 Alternative execution(可选择的运行方式)

branch: One of the alternative sequences of statements in a conditional statement.

#5.5 案例
if x%2==0:
    print(x+'is even')
else:
    print(x+'is odd')

5.6 Chained conditionals(链状条件语句)

chained conditional: A conditional statement with a series of alternative branches.

def compare_xy(x,y):
    i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值