python-作业-1

 环境变量修改: 我的电脑---高级系统设置---环境变量---Path---选择要修改的变量,用分号割开;

兼容python2的编码 #/usr/bin/u/ubv/a python     

          # -*- coding:utf-8 -*-

1.使用while循环输入 1 2 3 4 5 6   8 9 10

i = 1
while i<11:
    if i == 7:
        pass
    else:
        print(i)
    i = i + 1
----------------------------------
count = 0
while count < 11:
    if count == 6:
        count = count + 2
    else:
        count = count + 1
    print(count)

2. 求 1-100的所有数的和

n = 1
s = 0
while n < 101:
    s = s + n
    n = n + 1

print(s)
--------------------------------------
i = 0
j = 0
while i < 100:
    i = i + 1
    j = j + i
    print(j)

3. 输出1-100内的所有奇数

n = 1
while n < 101:
    temp = n % 2
    if temp == 0:
        pass
    else:
        print(n)
    n = n + 1
---------------------------------------------------
n = 1
while n <101:
    print(n)
    n = n + 2

4. 输出1-100内的所有偶数

i = 1
while i < 101:
    temp = i % 2
    if temp == 1:
        pass
    else:
        print(i)
    i = i + 1
--------------------------------------
i = 2

while i < 101:
    print(i)
    i = i + 2

5. 求1-2+3-4+5....99的所有数的和

i = 0
s = 0

while i < 100:
    temp = i % 2
    if temp == 1:
        s = s + i
    else:
        s = s - i
    i = i + 1
print(s)
----------------------------------
i = 1
odd = 0
even = 0
while i < 100:
    if i%2 == 1:
        odd = odd + i
    elif i%2 == 0:
        even = even + i
    i = i + 1
print(odd - even)

 

posted @ 2018-05-15 10:50  marypy  阅读(150)  评论(0)    收藏  举报