**Instructor: Mr. Bankat**
**This Week’s Topics**
During my Week 9 at blockfuse labs, we delved into Conditionals, the match-case statement, and briefly discussed Dictionaries. These concepts are essential for making decisions in Python and for arranging data in an organized manner.
In Python, conditionals enable our programs to make choices based on specific conditions.
``` python
if 10 < 20:
print("Condition one is true.")
elif 15 == 15:
print("Condition two is true.")
else:
print("Neither condition is true.")
```
***Key Points***:
- The "if" statement checks the initial condition.
- The "elif" (else if) statement assesses additional possibilities.
- The "else" statement serves as a default option if none of the conditions are satisfied or met.***
**The match-case Construct**
The statement used for matching cases. The match–case structure is comparable to switch statements found in other programming languages. It provides a more organized way to evaluate multiple conditions.
``` python
fruit = "Apple"
match fruit:
case "Apple":
print("An apple a day keeps the doctor away.")
case "Banana":
print("Bananas are rich in potassium.")
case _:
print("Unknown fruit.")
```
**Bringing everything together, we have:**
```python
grades = {
"Alice": 92,
"Bob": 65,
"Charlie": 40
}
student_name = input("Enter the student's name: ")
if student_name in grades:
student_score = grades[student_name]
match student_score:
case score if score >= 70:
print(f"{student_name} achieved an excellent result.")
case score if score >= 50:
print(f"{student_name} passed the test.")
case _:
print(f"{student_name} did not pass.")
else:
print("No record found for that student.")
```
# Conclusion
In Week 9, we discovered how to:
- Utilize if–elif–else for decision-making.
- Apply match–case for more organized branching.
- Handle dictionaries to manage structured data.
As we progress, these tools will be vital for developing more interactive and intelligent Python applications
**Written by: Elkanah Zokdat.**