4.
4. Write a program where the user manually selects options (e.g., "1. Fill Jug A", "2. Empty Jug B")
to reach a goal state of 2 Litres. (Simulation only).
# 4. Python Program to Simulate Water Jug Problem
### Program
```python
# Water Jug Problem - Simulation
jug_a = 0
jug_b = 0
print("Water Jug Problem")
print("Goal: Obtain exactly 2 Litres")
while True:
print("\nCurrent State:")
print("Jug A =", jug_a, "Litres")
print("Jug B =", jug_b, "Litres")
if jug_a == 2 or jug_b == 2:
print("\nGoal state reached!")
break
print("\nChoose an operation:")
print("1. Fill Jug A")
print("2. Fill Jug B")
print("3. Empty Jug A")
print("4. Empty Jug B")
print("5. Pour A into B")
print("6. Pour B into A")
print("7. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
jug_a = 4
elif choice == 2:
jug_b = 3
elif choice == 3:
jug_a = 0
elif choice == 4:
jug_b = 0
elif choice == 5:
amount = min(jug_a, 3 - jug_b)
jug_a -= amount
jug_b += amount
elif choice == 6:
amount = min(jug_b, 4 - jug_a)
jug_b -= amount
jug_a += amount
elif choice == 7:
print("Simulation ended.")
break
else:
print("Invalid choice!")
```
### Sample Output
```text
Water Jug Problem
Goal: Obtain exactly 2 Litres
Current State:
Jug A = 0 Litres
Jug B = 0 Litres
Choose an operation:
1. Fill Jug A
2. Fill Jug B
3. Empty Jug A
4. Empty Jug B
5. Pour A into B
6. Pour B into A
7. Exit
Enter your choice: 2
Current State:
Jug A = 0 Litres
Jug B = 3 Litres
Enter your choice: 6
Current State:
Jug A = 3 Litres
Jug B = 0 Litres
Enter your choice: 2
Current State:
Jug A = 3 Litres
Jug B = 3 Litres
Enter your choice: 4
Current State:
Jug A = 3 Litres
Jug B = 0 Litres
Enter your choice: 6
Current State:
Jug A = 4 Litres
Jug B = 0 Litres
Enter your choice: 4
Current State:
Jug A = 4 Litres
Jug B = 0 Litres
```
**Note:** The program uses **Jug A = 4 litres** and **Jug B = 3 litres**. The user manually selects operations, and the program updates the current state after each operation.