-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoops.py
31 lines (18 loc) · 883 Bytes
/
Loops.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
# While Loops
# We can have the loop run indefinitely or (similar to an if statement) determine how many times the loop should run based on a condition.
i = 1
while i <= 10:
print(i)
i = i + 1
# For Loops
# A for loop is used to iterate over a sequence such as a list. Lists are used to store multiple items in a single variable, and are created using square brackets (see below).
websites = ["facebook.com", "google.com", "amazon.com"]
for site in websites:
print(site)
# Python code that will print the numbers from 0 to 4. In programming, 0 is often the starting number, so counting to 5 is 0 to 4 (but has 5 numbers: 0, 1, 2, 3, and 4)
for i in range(5):
print(i)
# On the code editor, click back on the "script.py" tab and code a loop that outputs every number from 0 to 50.
for i in range(0,51):
print(i)
# The flag is: THM{L00PS_WHILE_FOR}