-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_For_loop_tasks.py
More file actions
43 lines (34 loc) · 938 Bytes
/
Copy pathpython_For_loop_tasks.py
File metadata and controls
43 lines (34 loc) · 938 Bytes
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
43
# ============================================
# Task 1: Print numbers from 1 to 5 using range()
# ============================================
for i in range(1, 6):
print(i)
print() # separator
# ============================================
# Task 2: Print only odd numbers between 1 and 10
# using step parameter in range()
# ============================================
for i in range(1, 11, 2):
print(i)
print() # separator
# ============================================
# Task 3: Nested for loop to print pattern
# 0 0
# 0 1
# 1 0
# 1 1
# 2 0
# 2 1
# ============================================
for i in range(3):
for j in range(2):
print(i, j)
print() # separator
# ============================================
# Task 4: Print numbers from 1 to 7
# Stop loop immediately when number is 5
# ============================================
for i in range(1, 8):
if i == 5:
break
print(i)