Python教程(三)

条件判断

  • if-else

说明:elif 是 else if 的缩写,在每一个 if、elif(else if)、else 语句后面都要加上冒号

  • 示例代码
scoreStr = input("Please input your score:");
score = int(scoreStr);
PASS_SCORE = 60;
WELL_SCORE = 80;
EXCELLENT_SCORE = 90;
MAX_SCORE_LIMIT=100;
MIN_SCORE_LIMIT=0;
if score

循环

  • for
  • 示例代码
numberSeq=[1,3,5,7,8]
sum = 0
for x in numberSeq:
    sum+=x
print("sum=%d" % sum)
  • while
  • 示例代码
n = 100
sum = 0
while n>0 :
    sum+=n
    n-=1
print("sum=%d" % sum)

你可能感兴趣的:(Python教程(三))