#场景一:
for i in [2,4,6,8]:
print(i,end = “”)
#结果:2 4 6 8
#场景二:
for i in range(5):
print(i,end = “”)
#结果:0 1 2 3 4
#场景三:
for i in range(1,5):
print(i,end = “”)
#结果:1 2 3 4
#场景四:
for i in range(1,10, 2):
print(i,end = “”)
#结果:1 3 5 7 9
列子1:求1-100间5和7的倍数之和
sum_of_number = 0
for i in range(1,101):
if i % 5 ==0:
sum_of_number +=i
elif i % 7 ==0:
sum_of_number +=i
else:pass
print("\n 满足条件得数之和为:%d" %sum_of_number)#1680
列子1:求水仙花数(三位数)
#比如:153 = 13 + 53 + 33
sum_of_number = 0
for i in range(100,1000):
bai_number = str(i)[0]
shi_number = str(i)[1]
ge_number = str(i)[2]
if i == int(ge_number