我不知道该怎么做。我知道如何通过提示行和列来打印方形,但不太明白如何仅提示高度并打印偶数数组。
Leading
这就是我设置打印方形星号的方法,但是如果只提示高度并打印出偶数数字,我该怎么做呢?例如,如果我的身高是" 3",它应该打印出一个如下所示的数组:
@using (Html.BeginForm("Leading", "Home", FormMethod.Get))
{
<div class="col-sm-2">
@Html.DisplayNameFor(m => m.Leadings.FirstOrDefault().Type)
@Html.DropDownListFor(m => m.Type, Model.TypeList, new { @class = "form-control" })
</div>
<div class=" col-sm-2">
@Html.DisplayNameFor(m => m.Country)
@Html.DropDownListFor(m => m.Country, Model.CountriesList, new { @class = "form-control"})
</div>
<button type="submit" class="btn btn-info">Search</button>
}
答案 0 :(得分:0)
在next()
个数字上使用iterator
:
h = 3
ns = iter(range(0,h**2*2,2))
for r in range(h):
for c in range(h):
print(next(ns), end='\t')
print()
给出:
0 2 4
6 8 10
12 14 16
使用slicing
和str.join
:
h = 4
ns = list(range(0,h**2*2,2))
for r in range(0,len(ns),h):
print(" ".join(str(c) + "\t" for c in ns[r:r+h]))
给出:
0 2 4 6
8 10 12 14
16 18 20 22
24 26 28 30
答案 1 :(得分:0)
这是一种通过制作嵌套列表并使用格式化功能将其打印出来的方法。可以用大型列表的生成器理解来替换列表理解。
// setValue expects Integer (class)
// getValue returns Short (class)
intLength.setValue(shortLength.getValue());