-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.py
More file actions
50 lines (38 loc) · 779 Bytes
/
11.py
File metadata and controls
50 lines (38 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# coding=utf-8
#lambda表达式
def ds(s):
return 2*s+1
#lambda实现相同的函数功能
# a = lambda x:2*x+1
# print(a)
#lambda表达式简化了函数的定义过程
#输出1到100的偶数
start = 1
while True:
if start==51:
break
print(start*2)
start += 1
print('-------------------------')
#输出1到100的奇数
end = int(input('请输入计算的范围:'))
prior = 1;
while True:
if prior==100:
break
if prior%2==1:
print(prior)
prior += 1
print('-------------------------')
#计算1-2+3-4+5-6+..+99-100的和
sum = 0
symbol = 1
while True:
if symbol==end+1:
break
if symbol%2 == 1:
sum = sum + symbol
if start%2 == 0:
sum = sum - symbol
symbol += 1
print sum;