if <條件判斷1>:
?? <執(zhí)行1>
elif <條件判斷2>:
?? <執(zhí)行2>
elif <條件判斷3>:
?? <執(zhí)行3>
else:
?? <執(zhí)行4>
Python的循環(huán)有兩種嗤朴,一種是for...in循環(huán)复隆,依次把list或tuple中的每個元素迭代出來
sum = 0 for x in range(101): sum = sum + x print(sum)
第二種循環(huán)是while循環(huán),只要條件滿足,就不斷循環(huán)榄檬,條件不滿足時退出循環(huán)
sum = 0 n = 99 while n > 0: sum = sum + n n = n - 2 print(sum)