Python learning by case study@[April]
(跟着April用真实案例学Python)
Lesson five 第五讲
Python is one of the most popular programming languages in the world. It is necessary to grasp it before entering the workplace.
Python是世界上最流行的编程语言之一。 在进入职场前大家都有必要掌握这门语言。
TODAY’S FOCUS–“if…else”
今日学习:if…else 条件
一
Grammar:
基本语法:
if(condition1):
do something1
elif(condition2):
do something2
else:
do other thing
二
case 1
举例1
The ticket price of the zoo has 3 different levels,
for age 0-12, the price is $10,
for age 13-18, the price is $15,
for age older than 18, the price is $20.
动物园门票有三个档,
年龄0-12岁,票价10元。
年龄13-18岁,票价15元。
年龄大于18岁,票价20元。
Could you make an application by python to automatically calcuate the price for the visitor?
你可以写一个程序来帮助自动计算票价吗?
case 2
举例2
The post office have different price level for delivery and package.
if the quantitiy is less than 3, the package fee is free, and the delivery is $3/item;
if the quantitiy is between 3 and 10, the package fee is $2/item, and the delivery is $5/item;
if the quantitiy is more than 10, the package fee is $5/item, and the delivery is $10/item;
邮局的打包和邮寄费标准不同:
如果物品数量小于3个,打包费全免,邮寄费则是每件3元;
如果物品数量在3个至10个之间,打包费是每件2元,邮寄费则是每件5元;
如果物品数量大于10个,打包费是每件5元,邮寄费则是每件10元;
Could you make an application by python to automatically calcuate the price for the post office?
你可以写一个程序来帮助自动计算邮费吗?
三 condition 条件
and:
condition 1 and condition 2: both condition1 and conditon 2 need to meet, then be true.
or:
condition 1 or condition 2: condition1 could meet or condition2 could meet, then be true.
So, you have learnt python ‘if else’ in today’s lesson. See you next time.
今天,这节课里你学会了python里的 ‘if…else…’ 。下节课再见啦