Intelligent Assignmknent 2
Intelligent Assignmknent 2
ASSIGNMENT 2
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 = []
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.")
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:
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 :