Create for_loops_1

This commit is contained in:
Joe James
2020-02-25 08:06:39 -06:00
committed by GitHub
parent 19615a70fb
commit ecca009a78

17
python/for_loops_1 Normal file
View File

@@ -0,0 +1,17 @@
# m is a list of integers
m = [5,7,6,8,1,4,2,7]
# here number is just a variable name
# the for loop iterates each item in list m
# the print statement prints the number and the number squared
for number in m:
print(number, number**2)
# here i is a variable for the list index
# the for loop iterates from 0 (first item)
# through len(m) which is the last item
# the print statement prints the index i,
# and the i'th item in the list, m[i]
print()
for i in range(len(m)):
print(i, m[i])