美文网首页
《笨办法学Python3》练习三十:else-if

《笨办法学Python3》练习三十:else-if

作者: 雨开Ame | 来源:发表于2019-03-05 19:55 被阅读0次

练习代码

people = 30
cars = 40
trucks = 15

if cars > people:
    print("We should take the cars.")
elif cars < people:
    print("We can't decide.")

if trucks > cars:
    print("That's too many trucks.")
elif trucks < cars:
    print("Maybe we could take the trucks.")
else:
    print("We still can't decide.")

if people > trucks:
    print("Alright, let's just take the trucks.")
else:
    print("Fine, let's stay home then.")

Study Drills

  1. Try to guess what elif and else are doing.

  2. Change the numbers of cars, people, and trucks, and then trace through each
    if-statement to see what will be printed.

  3. Try some more complex Boolean expressions like cars > people or trucks < cars.

  4. Above each line write a comment describing what the line does.

相关文章

网友评论

      本文标题:《笨办法学Python3》练习三十:else-if

      本文链接:https://www.haomeiwen.com/subject/ntfauqtx.html