Discuss / Python / 作业题

### 作业题

Topic source

#### iiliul

#1 Created at ... [Delete] [Delete and Lock User]

``````#!/usr/bin/env python

def normalize(name):
return name[0].upper()+name[1:len(name)].upper().lower()

L2 = list(map(normalize, L1))
print(L2)
``````

``````#!/usr/bin/env python

from functools import reduce

def prod(L):
return reduce(lambda x,y:x*y,L)

print('3 * 5 * 7 * 9 =', prod([3, 5, 7, 9]))
``````

#### iiliul

#2 Created at ... [Delete] [Delete and Lock User]

``````def str2float(s):
def char2num(s):
return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]
l = s.split('.')
return reduce(lambda x, y: x * 10 + y, map(char2num, l[0])) + reduce(lambda x, y: x / 10 + y, map(char2num, l[1][::-1])) / 10
``````

#### 用户zm1t2ndahk

#3 Created at ... [Delete] [Delete and Lock User]

str2float('0.11') 0.11000000000000001

#### 用户zm1t2ndahk

#4 Created at ... [Delete] [Delete and Lock User]

str2float('0.11') (1.1, 0)

str2float('0.11') (0.11000000000000001, 0)

• 1