简体   繁体   English

您如何在列表理解中要求用户输入?

[英]How do you ask for user input in list comprehension?

I'm trying to figure out how to ask for a user's input in list comprehension format.我试图弄清楚如何以列表理解格式询问用户的输入。

SR = [srt for i in range (N) input("Enter a type of food")]
print (SR)

Assuming N was 2 for example, I would like to get a list that contains 2 user inputs essentially.例如,假设 N 为 2,我想获得一个包含 2 个用户输入的列表。 However the code about doesn't work.但是关于代码不起作用。

You have the syntax wrong.你有语法错误。 This is how you do it这就是你的做法

SR = [input("Enter a type of food: ") for _ in range (N)]

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

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