简体   繁体   English

有没有人可以在这个 python 代码中帮助我?

[英]is there anyone can help me in this python code?

Define a function that accepts a list (called numbers below) as input and return a list where each element is multiplied by 10. In this case, you need to write a function that will work for arbitrary input.定义一个 function,它接受一个列表(下面称为数字)作为输入并返回一个列表,其中每个元素都乘以 10。在这种情况下,您需要编写一个适用于任意输入的 function。 Before submitting your function to the grader, you may want to check that it returns the output that you expect by evaluating code similar to the following:在将 function 提交给评分者之前,您可能需要通过评估类似于以下的代码来检查它是否返回了您期望的 output:

test_numbers = [1, 2, 3]
mult(test_numbers)

any help?有什么帮助吗?

Simple solution using the list comprehension.使用列表理解的简单解决方案。

def multiply(lis):
    return [x * 10 for x in list]

This worked for me这对我有用

def multiply(input_list):
    return map(lambda a: a*10, input_list)

inp = map(int, input("Enter numbers seperated by comma(,):").split(','))

mul = multiply(inp)
for i in mul:
    print(i)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM