I want to print multiples of a number based on user input in one line using map. But the below code is only working for static inputs:
print(list(map(lambda n: 12 * n, [i for i in range(1, 11)])))
Use can give dynamic input like this:
print(list(map(lambda n,:12*n,[i for i in range(1,int(input()))])))
or can use it in for loop.
you will have to take the input from user first and then use map
and lambda
(one liner)
example:
user_input = int(input())
print(list(map(lambda n, : user_input * n, [i for i in range(1, int(input()))])))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.