<>习题01.

1st = [] for i in range(2000, 3201): if (i%7==0) and (i%5!==0) lst.append(str(i
)) print(','.join(lst))

# 方法一： for i in range(2000, 3201): if i % 7 == 0 and i % 5 != 0: print(i, end=
',') print() # 方法二： print(','.join(str(i) for i in range(2000, 3201) if i % 7 ==
0 and i % 5 != 0)) # 方法三： print(','.join(list(map(str, filter(lambda x: x % 7 ==
0 and x % 5 !=0, range(2000,3201))))))
<>习题02.

8

40320

def fact(x) if x == 0: return 1: return x * fact(x-1) x = int(input()) print
fact(x)

n = int(input()) # 方法一： s = 1 for i in range(1, n+1): s *= i print(s) # 方法二：
import math s2 = math.factorial(n) print(s2) # 方法三： from functools import reduce
s3= reduce(lambda x, y: x*y, range(1, n+1)) print(s3) # 方法四 def loop(n): if n
<= 0: return 1 else: return n * loop(n-1) s4 = loop(n) print(s4)
<>习题03.

8

{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}

n = int(input()) d = dict() for i in range(1, n+1)： d[i] = i*i print(d)

n = int(input()) # 方法一： d = {} for i in range(1, n+1): d[i] = i * i print(d) #

range(1, n+1)], [i*i for i in range(1, n+1)])) print(d2)
<>习题04.

34,67,55,33,12,98

[‘34’, ‘67’, ‘55’, ‘33’, ‘12’, ‘98’]
(‘34’, ‘67’, ‘55’, ‘33’, ‘12’, ‘98’)

values = input() 1st = values.split(",") t = tuple(1) print(lst) print(t)
<>习题05.

getString：从控制台输入获取字符串
printString：以大写形式输出字符串

class InputOutString: def __init__(self): self.s = "" def getString(self): self
.s = input() def printString(self): print self.s.upper() strObj = inputOutString
() strObj.getString() strObj.pringString()
<>习题06.

D为变量，其值应以逗号分隔，按顺序输入到程序中。

100,150,180

18,22,24

import math c = 50 h = 30 value = [] items = [x for x in input().split(',')]
for d in items: value.append(str(int(round(math.sqrt(2*c*float(d)/h))))) print(
','.join (value))
<>习题07.

3,5

[[0，0，0，0，0]，[0，1，2，3，4]，[0，2，4，6，8]]

input_str = input() dimensions = [int(x) for x in input_str.split(',')] rowNum
= dimensions[0] colNum = dimensions[1] multilist = [[0 for col in range(colNum)]
for row in range(rowNum)] for row in range(rowNum): for col in range(colNum):
multilist[row][col] = row*col print(multilist)

def lianxi_07(x, y): # 方法一： new_lst = [] for i in range(x): lst = [] for j in
range(y): lst.append(i * j) new_lst.append(lst) print(new_lst) # 方法二： print([[i
* j for j in range(y)] for i in range(x)]) lianxi_07(3, 5)
<>习题08.

without,hello,bag,world

bag,hello,without,world

items = [x for x in input().split(',')] items.sort() print(','.join(items))
<>习题09.

**编写一个程序，改程序接受序列作为输入，并能将输入句中的字母全部改为大写后输出。

Hello world
Practice makes perfect

HELLO WORLD
PRACTICE MAKES PERFECT
**

lines = [] while True: s = input() if s: lines.append(s.uppper()) else: break
for sentence in lines: print(sentence)
<>习题10.

hello world and practice makes perfect and hello world again

again and hello makes perfect practice world

s = input() words = [word for word in s.split(" ")] print(" ".join(sorted(list(
set(words)))))