# 1.for loop
# list
L1=[10,20,'ABC','python']
print(L1[0])
for i in L1:
print(i)
10
10
20
ABC
python
#range function , Generate a sequence
for i in range(10): #10 representative stop , Can't get
print(i,end=' ')
0 1 2 3 4 5 6 7 8 9
for i in range(5,10): # 5 representative start,10 representative stop
print(i,end=" ")
5 6 7 8 9
# 5 representative start,10 representative stop,2 representative sep
for i in range(5,10,2):
print(i)
5
7
9
# Calculation 1+2+...+100
# Writing a
sum=0
for i in range(1,101,1):
sum=sum+i
print("1 To 100 The sum of the :",sum)
1 To 100 The sum of the : 5050
# Calculation 1+2+...+100
# Write two :
sum=0
for i in range(101):
sum+=i
print("1 To 100 The sum of the :",sum)
1 To 100 The sum of the : 5050
#2.while loop
# Calculation 1+2+...+100
i=1;
sum=0
while i<=100:
sum=sum+i
i=i+1
print("1 To 100 The sum of the :",sum)
1 To 100 The sum of the : 5050