Skip to content

Commit ba7252a

Browse files
Update README.md
1 parent d0b806f commit ba7252a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Diff for: Day-07/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Conditional Statements in Python
2+
3+
Conditional statements are a fundamental part of programming that allow you to make decisions and execute different blocks of code based on certain conditions. In Python, you can use `if`, `elif` (short for "else if"), and `else` to create conditional statements.
4+
5+
## `if` Statement
6+
7+
The `if` statement is used to execute a block of code if a specified condition is `True`. If the condition is `False`, the code block is skipped.
8+
9+
```python
10+
if condition:
11+
# Code to execute if the condition is True
12+
```
13+
14+
- Example:
15+
16+
```python
17+
x = 10
18+
if x > 5:
19+
print("x is greater than 5")
20+
```
21+
22+
## `elif` Statement
23+
24+
The `elif` statement allows you to check additional conditions if the previous `if` or `elif` conditions are `False`. You can have multiple `elif` statements after the initial `if` statement.
25+
26+
```python
27+
if condition1:
28+
# Code to execute if condition1 is True
29+
elif condition2:
30+
# Code to execute if condition2 is True
31+
elif condition3:
32+
# Code to execute if condition3 is True
33+
# ...
34+
else:
35+
# Code to execute if none of the conditions are True
36+
```
37+
38+
- Example:
39+
40+
```python
41+
x = 10
42+
if x > 15:
43+
print("x is greater than 15")
44+
elif x > 5:
45+
print("x is greater than 5 but not greater than 15")
46+
else:
47+
print("x is not greater than 5")
48+
```
49+
50+
## `else` Statement
51+
52+
The `else` statement is used to specify a block of code to execute when none of the previous conditions (in the `if` and `elif` statements) are `True`.
53+
54+
```python
55+
if condition:
56+
# Code to execute if the condition is True
57+
else:
58+
# Code to execute if the condition is False
59+
```
60+
61+
- Example:
62+
63+
```python
64+
x = 3
65+
if x > 5:
66+
print("x is greater than 5")
67+
else:
68+
print("x is not greater than 5")
69+
```

0 commit comments

Comments
 (0)