-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforLoops.py
45 lines (29 loc) · 818 Bytes
/
forLoops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
print('my name is al')
for i in range(5):
print('hello world')
if(i == 3):
print('wow number 3')
print('printing the counter')
for i in range(10):
print('the count is ' + str(i))
#will print the i counter
#printing to 100
total = 0
for i in range(101):
total = total + i
print(str(total))
#printing to 100 using a while loop
total = 0
i = 0
while i < 100:
i = i + 1
total = total + i
print(total)
#range is a data object
print('my name is')
for i in range( 2,10) :
print('ishaq ' + str(i)) #range starts at 2, finishes at 9 (goes up to but does not include the value)
#range can be called with three arguments range(start, end, step)
for i in range(-2, 11, 2 ):
print (str(i))
#using a negative in the step argument of range, will make the counter count down