【发布时间】:2019-04-02 14:32:37
【问题描述】:
我想获取一个列表,提供一个范围内的特定要求 我的代码 只能将列表中的数字相乘。 我想在列表中乘以“数字平方”
例如: 定义的范围 = (1,200)
wanted_list =[1^2,2^2,3^2,...,(34 = 3^2 * 4^2),(35 = 3^2 * 5^2),..., (199 = 1^2 * 9^2 * 9^2)]
这是我的代码:
def mult(liste):
a=1
for i in liste:
a*=i #I think the problem is here
return a
listemm = [x for x in range(1,200)]
print(listemm)
qe= [mult(int(digit) for digit in str(numb)) for numb in listemm]
print(qe)
【问题讨论】:
-
还有什么问题?
-
一种快速而巧妙的解决方案是将整数转换为可迭代的字符串,在这种情况下,并计算它们的平方的乘积。否则,您必须使用正确的数学方法从整数中提取数字,除以 10 并保留提醒。
标签: python python-3.x list list-manipulation