求1-2+3-4+5 ... 99的所有數的和
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/5/6 0006 12:06
# @Author : Anthony.Waa
# @Site :
# @File : 求1-2+3-4+5 ... 99的所有數的和.py
# @Software: PyCharm
# demo1
count = 1
sum = 0
while count < 101:
if count % 2 == 1:
sum -= count
elif count % 2 == 0:
sum += count
count += 1
print(sum)
# ========================
# demo2
sum = 0
for count in range(1,101):
if count % 2 == 1:
sum -= count
elif count % 2 == 0:
sum += count
print(sum)
求1-2+3-4+5 ... 99的所有數的和
相關推薦
python入門:求1-2+3-4+5...99的所有數的和(自寫)
== 余數 奇數 nbsp int 當前 pre span bre 1 #!/usr/bin/env pyhton 2 # -*- coding:utf-8 -*- 3 #求1-2+3-4+5...99的所有數的和(自寫) 4 """ 5 給x賦值為0,給y賦值
python入門:求1-2+3-4+5...99的所有數的和
== python入門 ... sta rt+ color python while style 1 start =1 2 sum =0 3 while start <100: 4 if start % 2 ==0: 5 sum =sum -
求1-2+3-4+5 ... 99的所有數的和
file demo1 elif int sof usr software == python #!/usr/bin/env python# -*- coding: utf-8 -*-# @Time : 2018/5/6 0006 12:06# @Author : A
求 1-2+3-4+5-6+7-8....M 的結果算法
次數 pre blog spa rgs static console line span 1 static void Main(string[] args) 2 { 3 /** 4 * 算法題: 5 * 求 1-2+3-4+5-6+7
練習:求1+2+3+4+5...100的和
hid 技術 one brush src log display 分享 code 求1+2+3+4+5...100的和方法一 count = 1 s1 = 0 while count <= 100:
python練習題,寫一個方法 傳進去列表和預期的value 求出所有變量得取值可能性(例如list為[1,2,3,4,5,6,12,19],value為20,結果是19+1==20只有一種可能性),要求時間復雜度為O(n)
num bubuko com pri def 代碼 data- 取值 .com 題目:(來自光榮之路老師)a+b==valuea+b+c=valuea+b+c+d==valuea+b+c+d+...=valuea和b....取值範圍都在0-value寫一個方法 傳進去列
Java實現1-2+3-4+5-6...+99
java實現 static else sta sum main code sys oid 1 package test; 2 3 public class test2 { 4 public static void main(String[] args)
ACMNO.13求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一個數字。 輸入 n 輸出 和 樣例輸入 5 樣例輸出 153
題目描述 求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一個數字。 輸入 n 輸出 和 樣例輸入 5 樣例輸出 153 來源/分類 C語言 題目截圖: 思路: 首先要想到使用兩個for迴圈語句,進行巢狀迴圈!
【Java】給定一個字串str,和一個字母ch,請實現相應的程式碼求出一個數組,使陣列中每個數字表示該位置與字母ch之間的最短距離。 比如str=”lexinfintech” ch=”i” 則輸出為:[3,2,1,0,1,1,0,1,2,3,4,5]
import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * @author: ycz * @date: 2018/12/17 0017 16:43 * @description: */ p
在Sql中將 varchar 值 '1,2,3,4,5,6' 轉換成數據類型 int
給定 序列 顯示 結果 空格 sel -方法 一個表 affect --問題:將aa轉換為Int類型失敗 string aa="3,5,11,56,88,45,23"; select * from ERPBuMen where ID in(aa) ; --方法sel
寫一個函數計算但參數為n(n很大)時的值1-2+3-4+5-6+7……+n。(考慮程序執行效率)
參數 color n) col sys class n-1 == code 1 private static void jisuan(int n) { 2 int sum=0; 3 if(n%2==0){ 4 sum=-(n/2)
94、tensorflow實現語音識別0,1,2,3,4,5,6,7,8,9
結果 test amp building pre cti fun ner edi ‘‘‘ Created on 2017年7月23日 @author: weizhen ‘‘‘ #導入庫 from __future__ import division,print_func
01 使用while 循環輸入1 2 3 4 5 6 8 9 10
輸入 while == pos bre blog body while 循環 break start = 1while True: if start == 7: start += 1 continue print(start)
輸入一個矩陣,按照從外向裡以順時針的順序依次打印出每一個數字,例如,如果輸入如下4 X 4矩陣: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 則依次打印出數字1,2,
public ArrayList<Integer> printMatrix(int [][] matrix) { ArrayList<Integer> l1= new ArrayList<>(); &
如何使用迴圈計算1 + 2 +3 + 4 + 5 + 6 + 8 + 9 + 10的值
1、先嚐試輸出不包含7 第一種方式(在等於7時加1然後繼續下次迴圈) count = 1 while count <= 10: if count == 7: count += 1 # 如果等於7 在count=7的基礎上加1 然後繼續執行迴圈 co
輸入兩個整數序列,第一個序列表示棧的壓入順序,請判斷第二個序列是否可能為該棧的彈出順序。假設壓入棧的所有數字均不相等。例如序列1,2,3,4,5是某棧的壓入順序,序列4,5,3,2,1是該壓棧序列對應
輸入兩個整數序列,第一個序列表示棧的壓入順序,請判斷第二個序列是否可能為該棧的彈出順序。假設壓入棧的所有數字均不相等。例如序列1,2,3,4,5是某棧的壓入順序,序列4,5,3,2,1是該壓棧序列對應 import java
ACMNO.21 C語言-逆序輸出 輸入10個數字,然後逆序輸出。 輸入 十個整數 輸出 逆序輸出,空格分開 樣例輸入 1 2 3 4 5 6 7 8 9 0
題目描述 輸入10個數字,然後逆序輸出。 輸入 十個整數 輸出 逆序輸出,空格分開 樣例輸入 1 2 3 4 5 6 7 8 9 0 樣例輸出 0 9 8 7 6 5 4 3 2 1 提示 陣列?堆疊? 來源/分類 C語言
山科java實驗3-3編寫一個方法,返回一個double型的二維陣列,陣列中的元素通過解析字串引數獲得。例如,字串引數:“1,2;3,4,5;6,7,8”,對應的陣列為: d[0,0
編寫一個方法,返回一個double型的二維陣列,陣列中的元素通過解析字串引數獲得。例如,字串引數:“1,2;3,4,5;6,7,8”,對應的陣列為: d[0,0] = 1.0 d[0,1
js每隔一秒列印1,2,3,4,5
js怎麼每隔一秒打印出數字呢? 方法一: 自執行函式 for (var i=0; i<5; i++) { (function (i) { setTimeout(() => console.log(i), 1000*
用while語句輸出1 2 3 4 5 6 8 9 10
The while time spa port else while語句 pre print import time count=1 while count<=10: print(count,time.time()) if count != 6: