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

被折叠的 条评论
为什么被折叠?



