如何简单地将此循环转换为从1到100计数,并显示数字?我最近开始编码。倒计时它工作正常,但我无法弄清楚如何从1 -100开始
query = (from t1 in query
join t2 in RepoTable2.AsQueryable() on t1.Id equals t2.IdTable1 into joint1t2
from t2 in joint1t2.DefaultIfEmpty() // DefaultIfEmpty is used for left joins
join t3 in RepoTable3.AsQueryable() on t2.Id equals t3.IdTable2 into joint2t3
from t3 in joint2t3.DefaultIfEmpty() // DefaultIfEmpty is used for left joins
where t3.Id== null
select t1);
答案 0 :(得分:4)
如果使用for循环,它会变得非常简单:
for number in range(1,101):
print(number)
从100下降到1:
for number in range(100,0,-1):
print(number)
答案 1 :(得分:1)
只需从1开始计数,更改检查语句以检查数字是否小于100,并使用" count = count + 1"应该工作,祝你好运!
答案 2 :(得分:1)
从1开始,并在达到100时将条件更改为中断。每个循环添加1个。
count = 1
while count <= 100:
print(count)
count += 1
答案 3 :(得分:1)
可以试试'逆转':
>>> for i in reversed(range(1,11)):
... print i
...
10
9
8
7
6
5
4
3
2
1
答案 4 :(得分:0)
基本上只是与你已经拥有的相反。
count = 1
while count < 101:
print(count)
count = count + 1
答案 5 :(得分:-2)
试试这个。
count = 0
while count <= 100:
print ("Count = ", count)
count = count + 1