def分类器(*参数):
big_numbers = []
small_numbers = []
for n in argument:
if n**5 >100000:
big_numbers.append (n**5)
else:
small_numbers.append(n**5)
print (f 'big numbers: {big_numbers} \n small numbers: {small_numbers}')
分类器(8,2,66,45,3,7,9)
我想在每个数字中添加函数打印的文本,例如:“太大了”,所以输出会是这样的: 10000太大,400000太大。
发布于 2022-06-27 08:08:09
尝试将其替换为您的append
如下:
big_numbers.append (f'{n**5} is too big')
发布于 2022-06-27 08:08:33
如果我对你说得对,你可以这么做:
big_nums = [1,2,3]
res = [f"{num} is too big"for num in big_nums]
print(res)
https://stackoverflow.com/questions/72768810
复制相似问题