AI file
AI file
UNIVERSITY
LAB FILE
Artificial Intelligence
CSE401
SOURCE CODE:
import random
def guess_the_number():
# Generate a random number between 1 and 100
target_number = random.randint(1, 100)
attempts = 6
print("Welcome to the Number Guessing Game!")
print("I have selected a number between 1 and 100.")
print(f"You have {attempts} attempts to guess it.")
guess_the_number()
OUTPUT:
EXPERIMENT 2
AIM: Write a program in python to implement water jug problem using BFS.
SOURCE CODE:
def display_state(state, operation):
print(f"State: {state} | Operation: {operation}")
def water_jug_problem():
initial_state = (0, 0)
goal_state = (2, 0)
knowledge_base = set()
states = [(initial_state, [])]
while states:
current_state, path = states.pop(0)
knowledge_base.add(current_state)
if current_state == goal_state:
print("\nGoal state reached!")
print("Path to solution:")
for step in path:
print(step)
return
a, b = current_state
possible_moves = [
((4, b), "Fill 4L jug"),
((a, 3), "Fill 3L jug"),
((0, b), "Empty 4L jug"),
((a, 0), "Empty 3L jug"),
((min(a + b, 4), max(0, b - (4 - a))), "Pour 3L to 4L"),
((max(0, a - (3 - b)), min(a + b, 3)), "Pour 4L to 3L"),
]
if __name__ == "__main__":
print("Initial State: (0, 0)")
water_jug_problem()
OUTPUT: