云学编程的第9天—【微软官方python入门教程 P19-P20笔记】2021-11-09 if条件语句

本文是云学编程的第9天笔记,聚焦微软官方Python入门教程的P19和P20部分。讲解了如何处理条件语句,包括比较运算符如>、<、>=、<=、==和!=。特别强调了在比较字符串时需要注意的事项。通过实例展示了代码如何根据不同的支付金额和税率来计算税款,揭示了条件语句使代码能够对不同情况作出反应的重要性。

P19 Handling conditions

 

Your code needs the ability to take different actions based on different conditions.

if price >= 1.00:
    tax=.07
eles:
    tax=0
    print(tax)

# > # < # >= # <= # == # !=

Be careful when comparing strings 

conuntry='CANADA'
if conuntry.lower()=='canada':
    print('oh look a canadian')
else:
    print('you are not from canada')

Conditions allow our code to react to different situations

P20 实操

price=input('how much did you pay?')
price=float(price)
if price >=1.00:
    tax= .07
    print('Tax rate is: '+str(tax))
else:
    price <1.00
    tax=0
    print('Tax rate is: '+str(tax))
price=input('how much did you pay?')
price=float(price)
if price >=1.00:
    tax =.07 
else:
    tax=0
print('Tax rate is: '+str(tax))

how much did you pay?9
Tax rate is: 0.07
how much did you pay?0.1
Tax rate is: 0

showing you the case sensitivity

country=input('enter the name of your home country: ')
if country.lower()=='canada':
    print('so you must like hockey!')
else:
    print('you are not from canada')

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值