返回列表 發帖

計算總和 (一)

計算 1+2+3+…+10 之和

  1. sum=0
  2. for i in range(1,11):
  3.     sum+=i
  4. print("1+2+3+...+10=%d"%sum)
複製代碼
  1. sum=0
  2. for i in range(1,11):
  3.     sum+=i   #sum=sum+i
  4. print("1+2+3+...+10={}".format(sum))
複製代碼

  1. for i in range(333,1000,3)
  2.   sum+i
  3.   print("333+...999=%d"%sum)  
複製代碼

TOP

  1. p=0
  2. for i in range(1,11):
  3.     p=p+i
  4.    
  5. print(p)
複製代碼

TOP

  1. sum=0
  2. for i in range(1,99):
  3.     sum=sum+i
  4. print(sum)
複製代碼

TOP

  1. for i in range(1,11):
  2.     sum+i
  3. print("1+2+3...+10=%d"%sum)
複製代碼

TOP

  1. sum=0
  2. for i in range(1,11):
  3.     sum+=i
  4. for i in range(100,0,-1):
  5.     print(i,end=" ")
複製代碼

TOP

  1. sum=0
  2. for i in range(1,11):
  3.     sum=sum+i
  4. print("1+2+3+4+5+6+7+8+9+10=",sum)
複製代碼

TOP

  1. sum=0
  2. for i in range(1,11):
  3.     sum=sum+i
  4. print("1+...+10",sum)
複製代碼

TOP

  1. sum=0
  2. for i in range(1,11):
  3.     sum=sum+i
  4. print("1+...+10=",sum)
複製代碼

TOP

  1. sum=0
  2. for i in range(1,11):
  3.     sum=sum+i
  4. print("1+...+10=",sum)
複製代碼

TOP

返回列表