2024-03-29 09:38:21 发布
网友
我编写了一个程序,要求用户输入如下四个数字:
a = input() first = int(a) b = input() second = int(b) c = input() third = int(c) d = input() fourth = int(d)
我不明白我怎么能把它们列在一个单子里。你知道吗
首先,可以使用空行,然后缩进4个空格,将代码放入代码块中。你知道吗
您可以将变量放入如下列表中:
list_variables = [first, second, third, fourth]
请注意,您可以使用列表理解:
lst = [int (input ()) for time in range (4)]
它使用一个简单的for循环执行int (input ())4次。现在您可以使用lst [0]、lst [1]、'lst [2]和lst [3]访问输入。你知道吗
for
int (input ())
lst [0]
lst [1]
'lst [2]
lst [3]
您应该稍微改进一下代码:
first = int(input()) second = int(input()) third = int(input()) fourth = int(input()) lst = [first, second, third, fourth]
首先,可以使用空行,然后缩进4个空格,将代码放入代码块中。你知道吗
您可以将变量放入如下列表中:
请注意,您可以使用列表理解:
它使用一个简单的
for
循环执行int (input ())
4次。现在您可以使用lst [0]
、lst [1]
、'lst [2]
和lst [3]
访问输入。你知道吗您应该稍微改进一下代码:
相关问题 更多 >
编程相关推荐