Python learning by case study@[April] (跟着April用真实案例学Python) lesson 5 if...elif...else

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?
你可以写一个程序来帮助自动计算票价吗?

case1-if else
case1-if else output
case1-if else output

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?
你可以写一个程序来帮助自动计算邮费吗?
case 2_if-else
case2_if-else
case2_if-else

三 condition 条件
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…’ 。下节课再见啦
case 3
case 3-output

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值