def xnor_gate(a, b):
if (a and b) or (not a and not b):
return 1
else:
return 0
# Test cases
input_values = [(0, 0), (0, 1), (1, 0), (1, 1)]
for a, b in input_values:
result = xnor_gate(a, b)
print(f"XNOR({a}, {b}) = {result}")
XNOR(0, 0) = 1
XNOR(0, 1) = 0
XNOR(1, 0) = 0
XNOR(1, 1) = 1
# Define logic gates functions
def and_gate(a, b):
return a and b
def or_gate(a, b):
return a or b
def xor_gate(a, b):
return (a and not b) or (not a and b)
# Interactive program
print("Logic Gate Simulator")
while True:
print("\nChoose a logic gate to simulate:")
print("1. AND Gate")
print("2. OR Gate")
print("3. XOR Gate")
choice = input("Enter your choice (1/2/3): ")
if choice == '1':
a = bool(int(input("Enter input A (0 or 1): ")))
b = bool(int(input("Enter input B (0 or 1): ")))
result = and_gate(a, b)
print(f"AND Gate result: {int(result)}")
break
elif choice == '2':
a = bool(int(input("Enter input A (0 or 1): ")))
b = bool(int(input("Enter input B (0 or 1): ")))
result = or_gate(a, b)
print(f"OR Gate result: {int(result)}")
break
elif choice == '3':
a = bool(int(input("Enter input A (0 or 1): ")))
b = bool(int(input("Enter input B (0 or 1): ")))
result = xor_gate(a, b)
print(f"XOR Gate result: {int(result)}")
break
else:
print("Invalid choice. Please select 1, 2, 3, or 4.")
Logic Gate Simulator
Choose a logic gate to simulate:
1. AND Gate
2. OR Gate
3. XOR Gate
AND Gate result: 0
def mark_homework(completed, on_time):
problem_incomplete = not completed
not_on_time = not on_time
incomplete = problem_incomplete or not_on_time
return "Incomplete" if incomplete else "Complete"
# Initialize a list of students with their completion and submission status
students = [
{"name": "Alice", "completed": True, "on_time": True},
{"name": "James", "completed": False, "on_time": True},
{"name": "Charlie", "completed": True, "on_time": False},
{"name": "David", "completed": False, "on_time": False},
]
# Create a dictionary to store the grades for each student
grades = {}
# Grade each student's homework
for student in students:
name = student["name"]
completed = student["completed"]
on_time = student["on_time"]
result = mark_homework(completed, on_time)
grades[name] = result
# Print the grades
for name, grade in grades.items():
print(f"{name}'s Homework Status: {grade}")
Alice's Homework Status: Complete
James's Homework Status: Incomplete
Charlie's Homework Status: Incomplete
David's Homework Status: Incomplete