【Python从零开始】第十二回_Python基础之"if语句的使用"
2017-09-06
if控制流语句执行条件原理
if cars > people: print(“We should take the cars.”) elif cars < people: print(“We should not take the cars.”) else: print(“We can’t dicide.”)
if buses > cars: print “That’s too many buses.” elif buses < cars: print(“Maybe we could take the buses.”) else: print(“We still can’t decide.”)
if people > buses: print(“Alright, let’s just take the buses.”) else: print(“Fine, let’s stay home then.”)
<br />
实例3
```py
num = int(input("enter number"))
if num%2 == 0:
if num%3 == 0:
print ("Divisible by 3 and 2")
else:
print ("divisible by 2 not divisible by 3")
else:
if num%3 == 0:
print ("divisible by 3 not divisible by 2")
else:
print ("not Divisible by 2 not divisible by 3")