Skip to content

Commit 7c27c45

Browse files
Add files via upload
1 parent 9fc4a3f commit 7c27c45

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

week_6/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Nested Loops in Python
2+
3+
A nested loop refers to a loop that exists within another loop. It is commonly used to perform operations on multi-dimensional structures, such as matrices or grids.
4+
5+
### Example of a Nested Loop
6+
7+
Below is a basic example of a nested loop in Python:
8+
9+
```python
10+
for i in range(3): # Outer loop
11+
for j in range(2): # Inner loop
12+
print(f"i = {i}, j = {j}")
13+
```
14+
## Nested Loops in Python
15+
16+
A nested loop is a loop that exists inside another loop. This technique is particularly useful for iterating over multi-dimensional structures such as matrices or grids. Each loop in the nested structure is referred to as an "inner loop" and an "outer loop."
17+
18+
### Concept
19+
20+
- **Outer Loop:** This is the loop that contains one or more inner loops. It controls the overall iteration and determines how many times the inner loops will be executed.
21+
- **Inner Loop:** This loop is nested inside the outer loop and is executed for each iteration of the outer loop. It performs operations on each element of the structure as defined by the outer loop.
22+
23+
### Example
24+
25+
Consider the following example of nested loops to print values in a 2D grid:
26+
27+
```python
28+
for i in range(3): # Outer loop
29+
for j in range(2): # Inner loop
30+
print(f"i = {i}, j = {j}")
31+
```

week_6/seventh.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
number = int(input("Enter a number: "))
2+
3+
if number >= 0:
4+
if number == 0:
5+
print("The number is zero.")
6+
elif number > 0 and number <= 10:
7+
print("The number is between 1 and 10.")
8+
elif number > 10 and number <= 100:
9+
print("The number is between 11 and 100.")
10+
else:
11+
print("The number is greater than 100.")
12+
else:
13+
print("The number is negative.")

0 commit comments

Comments
 (0)