[英]how to print a specific line of a csv file in python based on user input?
[英]How to print multiples of a number based on user input in one line using map
我想使用 map 根據用戶輸入在一行中打印多個數字。 但以下代碼僅適用於 static 輸入:
print(list(map(lambda n: 12 * n, [i for i in range(1, 11)])))
使用可以像這樣給出動態輸入:
print(list(map(lambda n,:12*n,[i for i in range(1,int(input()))])))
或者可以在 for 循環中使用它。
您必須先從用戶那里獲取輸入,然后使用map
和lambda
(一個班輪)
例子:
user_input = int(input())
print(list(map(lambda n, : user_input * n, [i for i in range(1, int(input()))])))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.