0% found this document useful (0 votes)
6 views5 pages

Intelligent Assignmknent 2

The document contains two assignments focused on implementing knowledge-based problem-solving using Python. The first assignment involves creating a healthcare chatbot that diagnoses diseases based on user-reported symptoms, utilizing a predefined knowledge base and providing advice. The second assignment simulates signal propagation in a PCB using Depth-First Search (DFS) to explore all possible paths from a source node to a destination node.

Uploaded by

Wabe Guy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Intelligent Assignmknent 2

The document contains two assignments focused on implementing knowledge-based problem-solving using Python. The first assignment involves creating a healthcare chatbot that diagnoses diseases based on user-reported symptoms, utilizing a predefined knowledge base and providing advice. The second assignment simulates signal propagation in a PCB using Depth-First Search (DFS) to explore all possible paths from a source node to a destination node.

Uploaded by

Wabe Guy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: Harsh Jain

Enrollment No.: 0801EC221037

ASSIGNMENT 2

Objective: To understand and implement knowledge-based problem-solving using a use


case scenario and Python programming.

Scenario: Smart Healthcare Chatbot for Disease Diagnosis

Use Case Description:

A healthcare chatbot helps users identify potential diseases based on their symptoms. The
system has a knowledge base containing symptoms and their associated diseases. The
chatbot uses rule-based reasoning to suggest possible diseases and provide advice.

CODE:
knowledge_base = {
"fever": ["flu", "malaria", "typhoid"],
"cough": ["flu", "cold", "pneumonia"],
"headache": ["flu", "migraine", "tension"],
"muscle_pain": ["flu", "malaria"],
"fatigue": ["flu", "anemia", "overwork"],
"diarrhea": ["food_poisoning", "typhoid"]
}

advice = {
"flu": "Get rest, drink fluids, and consider over-the-counter medication.",
"malaria": "Seek immediate medical attention. Malaria requires prescription medication.",
"typhoid": "Seek immediate medical attention. Typhoid requires antibiotics.",
"cold": "Rest, drink fluids, and use over-the-counter medication for symptoms.",
"pneumonia": "Seek immediate medical attention. Pneumonia may require antibiotics.",
"migraine": "Rest in a dark, quiet room. Consider over-the-counter pain relief.",
"tension": "Relaxation techniques, stress management, and over-the-counter pain relief.",
"anemia": "Consult a doctor for diagnosis and treatment. Dietary changes may be
recommended.",
"overwork": "Reduce workload, get enough sleep, and consider stress management
techniques.",
"food_poisoning": "Rest, drink fluids, and consider over-the-counter medication for
nausea and diarrhea."
}

def chatbot():
print("Welcome to the Smart Healthcare Chatbot!")
print("Please enter your symptoms (separated by commas):")
user_symptoms = input().lower().split(",")
possible_diseases = []

for symptom in user_symptoms:


if symptom in knowledge_base:
possible_diseases.extend(knowledge_base[symptom])

possible_diseases = list(set(possible_diseases))

if possible_diseases:
print("Possible diseases:")
for disease in possible_diseases:
print(f"- {disease}")
print("\nAdvice:")
for disease in possible_diseases:
print(f"{disease}: {advice.get(disease, 'Consult a doctor for diagnosis.')}")
else:
print("No matching diseases found. Please consult a doctor.")

if name == " main ":


chatbot()
OUTPUT:
Name: Deepesh Malviya
Enrollment No.: 0801EC233D03

ASSIGNMENT 2
Objective: Using Depth-First Search (DFS) to simulate signal propagation in a
PCB (Printed Circuit Board) and explore all possible paths of the signal.
Solution:
PCB:
Nodes:A, B, C, D, E, F
Edges: A-B, A-C, B-D, C-E, D-F, E-F
Source: A
Destination: E

CODE:

def dfs_all_paths(graph, source, destination, path=None, visited=None):


if path is None:
path = []
if visited is None:
visited = set()

path.append(source)
visited.add(source)

if source == destination:
return [path.copy()] # Return the current path as a solution

all_paths = []
for neighbor in graph[source]:
if neighbor not in visited: # Avoid revisiting nodes
all_paths.extend(dfs_all_paths(graph, neighbor, destination, path, visited))

path.pop() # Backtrack
visited.remove(source)

return all_paths
# Example graph
graph = {
'A': ['B', 'C'],
'B': ['A', 'D'],
'C': ['A', 'E'],
'D': ['B', 'F'],
'E': ['C', 'F'],
'F': ['D', 'E']
}
# Input
source = 'A'
destination = 'E'
# Output
all_paths = dfs_all_paths(graph, source, destination)
print("All Paths from Source to Destination:")
for path in all_paths:
print(" -> ".join(path))

if not all_paths:
print("No paths found. Possible dead ends.")

OUTPUT :

You might also like