1. 程式人生 > >奇數偶數

奇數偶數

== highlight eve div brush light print 偶數 end

奇數偶數以及差

odd = []
for i in range(1,101):
    if i % 2 != 0 :
        odd.append(i)
print(odd)


even = []
for i in range(1,101):
    if i % 2 == 0:
        even.append(i)

print(even)
        

sum1 = 0
for a in odd:
    sum1 = sum1 + a

print(sum1)
    

sum2 = 0
for a in even:
    sum2 = sum2 + a

print(sum2)

print(sum1 - sum2)

  

奇數偶數