python学习11——if 语句。

people=int(input("How many people are there in this city?"))
cats = int(input("How many cats are there in this city?"))
dogs = int(input("How many dogs are there in this city?"))
if people < cats:
 print("Too many cats! The world is doomed!")
elif people > cats:
 print("Not many cats! The world is saved!")
else:
 print("We can't decide.")
dogs += 10
if people >= dogs:
 print ("People are greater than or equal to dogs.")
else:
 print("People are less than dogs")

输出结果:

注意:

if 、elif、else 后需要加冒号。

数值型数据需要使用int()

猜你喜欢

转载自www.cnblogs.com/shannon-V/p/9550102.html