Discuss / Python / 交作业(为什么'#'开头的行会自动变成标题呀)

交作业(为什么'#'开头的行会自动变成标题呀)

Topic source

qq842205264

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

from functools import reduce

def normalize(name): return name.capitalize() L1 = ['adam','LISA','barT'] L2 = list(map(normalize,L1)) print(L2)

def prod(L): def product(a,b): return ab return reduce(product,L) print('3579 = ',prod([2*n+1 for n in range(1,5)]))

def str2float(s): digits = {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '.': '.'} def char2num(c): return digits[c]
def s2int(a,b): return a*10 + b ls = list(map(char2num, s)) #转化成list p = ls.index('.') #'.'的索引 ls = ls[:p] + ls[p+1:] #删除掉'.' return reduce(s2int,ls) / pow(10, len(ls) - p) print('str2float(\'123.456\') =', str2float('123.456')) if abs(str2float('123.456') - 123.456) < 0.00001: print('测试成功!') else: print('测试失败!')

因为#是markdown的特殊字符呀,可以用\#转义或者用```python 这里是代码 ```


  • 1

Reply