0

from logic import *

AKnight = Symbol("A is a Knight") AKnave = Symbol("A is a Knave")

BKnight = Symbol("B is a Knight") BKnave = Symbol("B is a Knave")

CKnight = Symbol("C is a Knight") CKnave = Symbol("C is a Knave")

Puzzle 0

A says "I am both a knight and a knave."

knowledge0 = And( Biconditional(AKnave,Not(AKnight)), Biconditional(BKnave,Not(BKnight)), Biconditional(CKnave,Not(CKnight)),

Implication(AKnight,And(AKnight,AKnight)) ,And(Implication(AKnave,Not(And(AKnave,AKnave))))

)

Puzzle 1

A says "We are both knaves."

B says nothing.

knowledge1 = And(

Biconditional(AKnave,Not(AKnight)), Biconditional(BKnave,Not(BKnight)), Biconditional(CKnave,Not(CKnight)), Implication(AKnight,And(AKnave,BKnave)) ,And(Implication(AKnave,Not(And(AKnave,BKnave))))

)

Puzzle 2

A says "We are the same kind."

B says "We are of different kinds."

knowledge2 = And( Biconditional(AKnave,Not(AKnight)), Biconditional(BKnave,Not(BKnight)), Biconditional(CKnave,Not(CKnight)),

Implication(AKnight,Or(And(AKnight,BKnave),And(AKnight,BKnight))),And(Implication(AKnave,Not(Or(And(AKnight,BKnave),And(AKnight,BKnight))))),
Implication(BKnight,Or(And(AKnave,BKnight),And(BKnave,AKnight))),And(Implication(BKnave,Not(Or(And(AKnave,BKnight),And(BKnave,AKnight)))))

)

Puzzle 3

A says either "I am a knight." or "I am a knave.", but you don't know which.

B says "A said 'I am a knave'."

B says "C is a knave."

C says "A is a knight."

knowledge3 = And( Biconditional(AKnave,Not(AKnight)), Biconditional(BKnave,Not(BKnight)), Biconditional(CKnave,Not(CKnight)),

Implication(BKnight,(Implication(AKnight,AKnave),And(Implication(AKnave,Not(AKnave)))),And(Implication(BKnave,Not((Implication(AKnight,AKnave),And(Implication(AKnave,Not(AKnave)))))), Implication(BKnight,CKnave),And(BKnave,Not(CKnave)), Implication(CKnight,AKnave),And(CKnave,Not(AKnave))

)

def main(): symbols = [AKnight, AKnave, BKnight, BKnave, CKnight, CKnave] puzzles = [ ("Puzzle 0", knowledge0), ("Puzzle 1", knowledge1), ("Puzzle 2", knowledge2), ("Puzzle 3", knowledge3) ] for puzzle, knowledge in puzzles: print(puzzle) if len(knowledge.conjuncts) == 0: print(" Not yet implemented.") else: for symbol in symbols: if model_check(knowledge, symbol): print(f" {symbol}")

if name == "main": main()

I got the error##

Python38-32/python.exe" "c:/Users/Mzle.py" File "c:/Users/M Hasnain Sikander def main(): ^ SyntaxError: invalid syntax

You must log in to answer this question.

Browse other questions tagged .