# Statements, Indentation and Conditionals

## Data Analysis and Decision-Making: Extracting Quarters, Calculating Mean and Median, Attendance Evaluation, and Grading System

Published on July 8, 2023 by Pradeepchandra Reddy S C

Tags: Python, Programming ### Introduction:

In this article, we will explore various Python code snippets that focus on data analysis and decision-making tasks. We will cover topics such as extracting quarters from dates, calculating mean and median values, evaluating attendance for exams, and implementing a grading system based on given criteria. These examples highlight the practical use of Python in analyzing data, making decisions, and automating processes efficiently. Throughout the process, I gained insights into fundamental concepts conditional statements.

### Problem 1: Extracting Quarters from Dates

As an analyst, you were tasked with presenting quarterly performance results. To accomplish this, you needed to extract the corresponding quarter from a given date. By using if-else statements and considering the predefined date ranges, we can extract the quarter based on the input date provided by the user. This allows for easier categorization and analysis of data based on quarterly performance.

### Problem 2: Calculating Mean and Median Heights and Weights

Next, we explore measures of averages using a list of product prices. We calculate the mean by dividing the sum of the prices by the number of elements in the list. Then, we sort the list to find the median. Depending on whether the number of elements is odd or even, we determine the middle element(s) and compute the median accordingly. Finally, we compare the mean and median to determine which is greater.

### Problem 3: Evaluating Attendance for Exams

In an educational setting, attendance plays a crucial role in determining eligibility for exams. We take input from the user regarding the number of classes held and the number of classes attended. Using this information, we calculate the attendance percentage and determine whether the student is allowed to sit for the exam. By applying an if-else condition, we assess whether the attendance meets the required threshold (75% in this case) and provide the appropriate response.

### Problem 4: Implementing a Grading System

Schools often have predefined grading systems based on different score ranges. In this problem, we implement a grading system using if-elif-else statements. The program prompts the user to input their marks, and based on the specified score ranges, it assigns the corresponding grade. This automated grading system simplifies the evaluation process and allows for quick determination of grades based on performance.

### Conclusion:

In this article, we explored several Python code snippets that demonstrated data analysis and decision-making processes. We saw how to extract quarters from dates, calculate mean and median values for a dataset, evaluate attendance for exams based on defined criteria, and implement a grading system. These examples showcase the power and versatility of Python in conditional statements in handling data, making informed decisions, and automating tasks. Python's simplicity and extensive library support make it an excellent choice for data analysis and decision-making applications across various domains.