条件判断:
if 语句
if else 语句
循环:
range(5)是生成小于5的0,1,2,3,4,如果加上一个list[range(5)] 就是生成一个列表[0,1,2,3,4]
如果计算0-100的整数的相加和:
sum = 0
for i in range(101):
sum = sum+i
print(sum)
第二种是while循环,只要条件满足就一直循环,条件不满足退出循环。
(这里计算100以内的所有奇数的和)
sum = 0
n = 99
while n > 0:
sum = sum+n
n = n-2
print(sum)
TRANSLATE with x
English
TRANSLATE with
COPY THE URL BELOW
Back
EMBED THE SNIPPET BELOW IN YOUR SITE
Enable collaborative features and customize widget: Bing Webmaster Portal
Back
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/281943.html