0
当我想要我的代码做到这一点:停止用户输入使用地图功能在特定条件
- 输入的第一行包含一个整数ň表示元素在列表中的号码;
- 第二行由N输入由空格分隔。
例如输入
5
1 2 1 1 2 2
由6个数字,但是,它应被限制到的输入端的数量为5。
这是到目前为止我的代码:
N = int(input(""))
nums = list(map(int, input("").split(" ")))
count, idx, var, index = 0, 0, 0, 0
for idx, j in enumerate(nums):
if index == idx:
var = var + j
index = var
if idx == (N-1): continue
elif j == 0 or j > N:
count = -1
break
else: count += 1
print(count)
究竟是什么问题?通过“将输入数量限制为5”,是否意味着忽略超过5的输入,或者使用户无法输入超过5个输入或其他内容? –
你是说在一条线上有更多的输入吗? – Tobias
你想让用户只输入5个输入吗? –