2. Write a program to demonstrate Logistic Regression to predict a "Pass" or "Fail" outcome based
on study hours.
# 2. Python Program to Demonstrate Logistic Regression
### Program
```python
# Logistic Regression - Pass or Fail Prediction
from sklearn.linear_model import LogisticRegression
# Hardcoded dataset
# Study hours
study_hours = [[1], [2], [3], [4], [5], [6], [7], [8]]
# 0 = Fail, 1 = Pass
result = [0, 0, 0, 0, 1, 1, 1, 1]
# Create Logistic Regression model
model = LogisticRegression()
# Train the model
model.fit(study_hours, result)
# Get study hours from user
hours = float(input("Enter study hours: "))
# Predict Pass or Fail
prediction = model.predict([[hours]])
if prediction[0] == 1:
print("Result: Pass")
else:
print("Result: Fail")
```
### Sample Output 1
```text
Enter study hours: 6
Result: Pass
```
### Sample Output 2
```text
Enter study hours: 2
Result: Fail
```
### Explanation
* `study_hours` contains the input data.
* `result` contains the output: **0 = Fail** and **1 = Pass**.
* `LogisticRegression()` creates the classification model.
* `fit()` trains the model using the hardcoded data.
* `predict()` predicts whether the student will **Pass or Fail** based on study hours.